os/security/crypto/weakcryptospi/test/kms/driver/test/kmslddtest/delete.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     5 * under the terms of the License "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description: 
    15 * Tests deleting a key from the hardware store.
    16 *
    17 */
    18 
    19 
    20 /**
    21  @file
    22 */
    23 
    24 #include "kmslddtest.h"
    25 
    26 
    27 TInt DeleteSingleKeySync(TKeyHandle aHandle)
    28 /**
    29 	Delete a single key using the global channel object.  This function
    30 	is provided for convenience, so the caller does not have to set up
    31 	their own TRequestStatus object.
    32 
    33 	@param	aHandle			Key to delete.
    34 	@return					Symbian OS error code with which the driver completed
    35 							the request.
    36  */
    37 	{
    38 	TRequestStatus rs;
    39 	KmsChannel.DeleteKey(CurrentProcess, aHandle, rs);
    40 	User::WaitForRequest(rs);
    41 	return rs.Int();
    42 	}
    43 
    44 void TestDeleteSingleKey(TKeyHandle aHandle, TInt aExpectedResult)
    45 /**
    46 	Attempt to delete a single key and test the request was completed
    47 	with the expected error code.
    48 
    49 	@param	aHandle			Key to delete.
    50 	@param	aExpectedResult	Expected Symbian OS error code with which the
    51 							driver is expected to complete the request.
    52  */
    53 	{
    54 	TInt r = DeleteSingleKeySync(aHandle);
    55 	test(r == aExpectedResult);
    56 	}
    57 
    58 static TInt TestDeleteKeyNotCreator(RProcess aProcess)
    59 /**
    60 	Attempt to delete a key with the supplied process as the claimed
    61 	owner.  This function is defined to test the driver the correctly
    62 	polices key deletion according to the claimed owner.
    63 
    64 	@param	aProcess		Process which claims to own, and can therefore
    65 							delete, the key.
    66 	@return					Error code with which the driver completed the
    67 							request.
    68  */
    69 	{
    70 	TRequestStatus rs;
    71 	KmsChannel.DeleteKey(aProcess, GenKeyHandle0, rs);
    72 	return rs.Int();
    73 	}
    74 
    75 void TestDeleteKey()
    76 /**
    77 	Test deleting keys from the hardware store.  See in-function
    78 	comments for specific test cases.
    79  */
    80 	{
    81 	test.Start(_L(" @SYMTestCaseID:SEC-CRYPTOSPI-DELETE-0001 TestDeleteKey "));
    82 	
    83 	TestGenerateSingleKey(1, CurrentProcess, GenKeyHandle0, KErrNone);
    84 	TestGenerateSingleKey(1, CurrentProcess, GenKeyHandle1, KErrNone);
    85 	TestGenerateSingleKey(1, CurrentProcess, StoreKeyHandle0, KErrNone);
    86 	TestGenerateSingleKey(1, CurrentProcess, StoreKeyHandle1, KErrNone);
    87 	
    88 	TestDeleteSingleKey(GenKeyHandle0, KErrNone);
    89 	TestDeleteSingleKey(GenKeyHandle1, KErrNone);
    90 	TestDeleteSingleKey(StoreKeyHandle0, KErrNone);
    91 	TestDeleteSingleKey(StoreKeyHandle1, KErrNone);
    92 	
    93 	// error case - non-existent handle
    94 	TestDeleteSingleKey(GenKeyHandle0, KErrNotFound);
    95 	TestDeleteSingleKey(GenKeyHandle1, KErrNotFound);
    96 	TestDeleteSingleKey(StoreKeyHandle0, KErrNotFound);
    97 	TestDeleteSingleKey(StoreKeyHandle1, KErrNotFound);
    98 
    99 	// error case - not deleted by creator
   100 	TestGenerateSingleKey(3, GenKeyHandle0, KErrNone);
   101 	TestSecondProcess(/* aCapabilityMask */ 0, /* aSecureId */ 0, TestDeleteKeyNotCreator, KErrPermissionDenied);
   102 	TestDeleteSingleKey(GenKeyHandle0, KErrNone);
   103 
   104 	DeleteAllKeys();
   105 	
   106 	test.End();
   107 	}
   108