MYPublicKey.m
changeset 9 aa5eb3fd6ebf
parent 3 1dfe820d7ebe
child 13 6fd9177eb6da
     1.1 --- a/MYPublicKey.m	Wed Apr 08 16:30:52 2009 -0700
     1.2 +++ b/MYPublicKey.m	Sun Apr 12 22:16:14 2009 -0700
     1.3 @@ -85,6 +85,42 @@
     1.4  }
     1.5  
     1.6  
     1.7 +#if !TARGET_OS_IPHONE
     1.8 +- (CSSM_WRAP_KEY*) _unwrappedCSSMKey {
     1.9 +    const CSSM_KEY *key = self.cssmKey;
    1.10 +    
    1.11 +    if (key->KeyHeader.BlobType == CSSM_KEYBLOB_WRAPPED) {
    1.12 +        Warn(@"Key is already wrapped.\n");
    1.13 +        return NULL;
    1.14 +    }
    1.15 +    
    1.16 +    if (key->KeyHeader.KeyClass != CSSM_KEYCLASS_PUBLIC_KEY)
    1.17 +        Warn(@"Warning: Null wrapping a non-public key - this is a dangerous operation.\n");
    1.18 +    
    1.19 +    const CSSM_ACCESS_CREDENTIALS* credentials;
    1.20 +    credentials = [self cssmCredentialsForOperation: CSSM_ACL_AUTHORIZATION_EXPORT_WRAPPED
    1.21 +                                               type: kSecCredentialTypeDefault error: nil];
    1.22 +    CSSM_CC_HANDLE ccHandle;
    1.23 +    if (!checkcssm(CSSM_CSP_CreateSymmetricContext(self.cssmCSPHandle, 
    1.24 +                                                   CSSM_ALGID_NONE, CSSM_ALGMODE_WRAP, 
    1.25 +                                                   NULL, NULL, NULL, 
    1.26 +                                                   CSSM_PADDING_NONE, NULL, 
    1.27 +                                                   &ccHandle),
    1.28 +                   @"CSSM_CSP_CreateSymmetricContext"))
    1.29 +        return NULL;
    1.30 +                   
    1.31 +    CSSM_WRAP_KEY *result = malloc(sizeof(CSSM_WRAP_KEY));
    1.32 +    if (!checkcssm(CSSM_WrapKey(ccHandle, credentials, key, NULL, result),
    1.33 +                      @"CSSM_WrapKey")) {
    1.34 +        free(result);
    1.35 +        result = NULL;
    1.36 +    }
    1.37 +    CSSM_DeleteContext(ccHandle);
    1.38 +    return result;
    1.39 +}
    1.40 +#endif
    1.41 +
    1.42 +
    1.43  @end
    1.44  
    1.45