2 * The contents of this file are subject to the Mozilla Public
3 * License Version 1.1 (the "License"); you may not use this file
4 * except in compliance with the License. You may obtain a copy of
5 * the License at http://www.mozilla.org/MPL/
7 * Software distributed under the License is distributed on an "AS
8 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
9 * implied. See the License for the specific language governing
10 * rights and limitations under the License.
12 * The Original Code is the Netscape security libraries.
14 * The Initial Developer of the Original Code is Netscape
15 * Communications Corporation. Portions created by Netscape are
16 * Copyright (C) 1994-2000 Netscape Communications Corporation. All
21 * Alternatively, the contents of this file may be used under the
22 * terms of the GNU General Public License Version 2 or later (the
23 * "GPL"), in which case the provisions of the GPL are applicable
24 * instead of those above. If you wish to allow use of your
25 * version of this file only under the terms of the GPL and not to
26 * allow others to use your version of this file under the MPL,
27 * indicate your decision by deleting the provisions above and
28 * replace them with the notice and other provisions required by
29 * the GPL. If you do not delete the provisions above, a recipient
30 * may use your version of this file under either the MPL or the
35 * Stuff specific to S/MIME policy and interoperability.
41 #include "SecAsn1Item.h"
43 #include "SecSMIMEPriv.h"
45 #include <security_asn1/secasn1.h>
46 #include <security_asn1/secerr.h>
47 #include <Security/SecSMIME.h>
48 #include <Security/SecKeyPriv.h>
50 SEC_ASN1_MKSUB(CERT_IssuerAndSNTemplate
)
51 SEC_ASN1_MKSUB(SEC_OctetStringTemplate
)
52 SEC_ASN1_CHOOSER_DECLARE(CERT_IssuerAndSNTemplate
)
54 /* various integer's ASN.1 encoding */
55 static unsigned char asn1_int40
[] = { SEC_ASN1_INTEGER
, 0x01, 0x28 };
56 static unsigned char asn1_int64
[] = { SEC_ASN1_INTEGER
, 0x01, 0x40 };
57 static unsigned char asn1_int128
[] = { SEC_ASN1_INTEGER
, 0x02, 0x00, 0x80 };
59 /* RC2 algorithm parameters (used in smime_cipher_map) */
60 static SecAsn1Item param_int40
= { sizeof(asn1_int40
), asn1_int40
};
61 static SecAsn1Item param_int64
= { sizeof(asn1_int64
), asn1_int64
};
62 static SecAsn1Item param_int128
= { sizeof(asn1_int128
), asn1_int128
};
65 * XXX Would like the "parameters" field to be a SecAsn1Item * , but the
66 * encoder is having trouble with optional pointers to an ANY. Maybe
67 * once that is fixed, can change this back...
70 SecAsn1Item capabilityID
;
71 SecAsn1Item parameters
;
72 long cipher
; /* optimization */
75 static const SecAsn1Template NSSSMIMECapabilityTemplate
[] = {
77 0, NULL
, sizeof(NSSSMIMECapability
) },
79 offsetof(NSSSMIMECapability
,capabilityID
), },
80 { SEC_ASN1_OPTIONAL
| SEC_ASN1_ANY
,
81 offsetof(NSSSMIMECapability
,parameters
), },
85 static const SecAsn1Template NSSSMIMECapabilitiesTemplate
[] = {
86 { SEC_ASN1_SEQUENCE_OF
, 0, NSSSMIMECapabilityTemplate
}
90 * NSSSMIMEEncryptionKeyPreference - if we find one of these, it needs to prompt us
91 * to store this and only this certificate permanently for the sender email address.
94 NSSSMIMEEncryptionKeyPref_IssuerSN
,
95 NSSSMIMEEncryptionKeyPref_RKeyID
,
96 NSSSMIMEEncryptionKeyPref_SubjectKeyID
97 } NSSSMIMEEncryptionKeyPrefSelector
;
100 NSSSMIMEEncryptionKeyPrefSelector selector
;
102 SecCmsIssuerAndSN
*issuerAndSN
;
103 SecCmsRecipientKeyIdentifier
*recipientKeyID
;
104 SecAsn1Item
*subjectKeyID
;
106 } NSSSMIMEEncryptionKeyPreference
;
108 extern const SecAsn1Template SecCmsRecipientKeyIdentifierTemplate
[];
110 static const SecAsn1Template smime_encryptionkeypref_template
[] = {
112 offsetof(NSSSMIMEEncryptionKeyPreference
,selector
), NULL
,
113 sizeof(NSSSMIMEEncryptionKeyPreference
) },
114 { SEC_ASN1_POINTER
| SEC_ASN1_CONTEXT_SPECIFIC
| SEC_ASN1_XTRN
| 0,
115 offsetof(NSSSMIMEEncryptionKeyPreference
,id
.issuerAndSN
),
116 SEC_ASN1_SUB(SecCmsIssuerAndSNTemplate
),
117 NSSSMIMEEncryptionKeyPref_IssuerSN
},
118 { SEC_ASN1_POINTER
| SEC_ASN1_CONTEXT_SPECIFIC
| 1,
119 offsetof(NSSSMIMEEncryptionKeyPreference
,id
.recipientKeyID
),
120 SecCmsRecipientKeyIdentifierTemplate
,
121 NSSSMIMEEncryptionKeyPref_IssuerSN
},
122 { SEC_ASN1_POINTER
| SEC_ASN1_CONTEXT_SPECIFIC
| SEC_ASN1_XTRN
| 2,
123 offsetof(NSSSMIMEEncryptionKeyPreference
,id
.subjectKeyID
),
124 SEC_ASN1_SUB(kSecAsn1OctetStringTemplate
),
125 NSSSMIMEEncryptionKeyPref_SubjectKeyID
},
129 /* smime_cipher_map - map of SMIME symmetric "ciphers" to algtag & parameters */
131 unsigned long cipher
;
134 Boolean enabled
; /* in the user's preferences */
135 Boolean allowed
; /* per export policy */
136 } smime_cipher_map_entry
;
138 /* global: list of supported SMIME symmetric ciphers, ordered roughly by increasing strength */
139 static smime_cipher_map_entry smime_cipher_map
[] = {
140 /* cipher algtag parms enabled allowed */
141 /* ---------------------------------------------------------------------------------- */
142 { SMIME_RC2_CBC_40
, SEC_OID_RC2_CBC
, ¶m_int40
, PR_FALSE
, PR_FALSE
},
143 { SMIME_DES_CBC_56
, SEC_OID_DES_CBC
, NULL
, PR_TRUE
, PR_FALSE
},
144 { SMIME_RC2_CBC_64
, SEC_OID_RC2_CBC
, ¶m_int64
, PR_FALSE
, PR_FALSE
},
145 { SMIME_RC2_CBC_128
, SEC_OID_RC2_CBC
, ¶m_int128
, PR_FALSE
, PR_FALSE
},
146 { SMIME_DES_EDE3_168
, SEC_OID_DES_EDE3_CBC
, NULL
, PR_TRUE
, PR_TRUE
},
147 { SMIME_AES_CBC_128
, SEC_OID_AES_128_CBC
, NULL
, PR_TRUE
, PR_TRUE
},
148 { SMIME_AES_CBC_192
, SEC_OID_AES_192_CBC
, NULL
, PR_TRUE
, PR_TRUE
},
149 { SMIME_AES_CBC_256
, SEC_OID_AES_256_CBC
, NULL
, PR_TRUE
, PR_TRUE
},
150 { SMIME_FORTEZZA
, SEC_OID_FORTEZZA_SKIPJACK
, NULL
, PR_TRUE
, PR_TRUE
}
152 static const int smime_cipher_map_count
= sizeof(smime_cipher_map
) / sizeof(smime_cipher_map_entry
);
155 * smime_mapi_by_cipher - find index into smime_cipher_map by cipher
158 smime_mapi_by_cipher(unsigned long cipher
)
162 for (i
= 0; i
< smime_cipher_map_count
; i
++) {
163 if (smime_cipher_map
[i
].cipher
== cipher
)
164 return i
; /* bingo */
166 return -1; /* should not happen if we're consistent, right? */
170 * NSS_SMIME_EnableCipher - this function locally records the user's preference
173 SecSMIMEEnableCipher(unsigned long which
, Boolean on
)
178 mask
= which
& CIPHER_FAMILYID_MASK
;
180 PORT_Assert (mask
== CIPHER_FAMILYID_SMIME
);
181 if (mask
!= CIPHER_FAMILYID_SMIME
)
182 /* XXX set an error! */
185 mapi
= smime_mapi_by_cipher(which
);
187 /* XXX set an error */
190 /* do we try to turn on a forbidden cipher? */
191 if (!smime_cipher_map
[mapi
].allowed
&& on
) {
192 PORT_SetError (SEC_ERROR_BAD_EXPORT_ALGORITHM
);
196 smime_cipher_map
[mapi
].enabled
= on
;
203 * this function locally records the export policy
206 SecSMIMEAllowCipher(unsigned long which
, Boolean on
)
211 mask
= which
& CIPHER_FAMILYID_MASK
;
213 PORT_Assert (mask
== CIPHER_FAMILYID_SMIME
);
214 if (mask
!= CIPHER_FAMILYID_SMIME
)
215 /* XXX set an error! */
218 mapi
= smime_mapi_by_cipher(which
);
220 /* XXX set an error */
223 smime_cipher_map
[mapi
].allowed
= on
;
229 * Based on the given algorithm (including its parameters, in some cases!)
230 * and the given key (may or may not be inspected, depending on the
231 * algorithm), find the appropriate policy algorithm specification
232 * and return it. If no match can be made, -1 is returned.
235 nss_smime_get_cipher_for_alg_and_key(SECAlgorithmID
*algid
, SecSymmetricKeyRef key
, unsigned long *cipher
)
241 algtag
= SECOID_GetAlgorithmTag(algid
);
243 case SEC_OID_RC2_CBC
:
244 keylen_bits
= CFDataGetLength((CFDataRef
)key
) * 8;
245 switch (keylen_bits
) {
247 c
= SMIME_RC2_CBC_40
;
250 c
= SMIME_RC2_CBC_64
;
253 c
= SMIME_RC2_CBC_128
;
259 case SEC_OID_DES_CBC
:
260 c
= SMIME_DES_CBC_56
;
262 case SEC_OID_FORTEZZA_SKIPJACK
:
265 case SEC_OID_DES_EDE3_CBC
:
266 c
= SMIME_DES_EDE3_168
;
268 case SEC_OID_AES_128_CBC
:
269 c
= SMIME_AES_CBC_128
;
271 case SEC_OID_AES_192_CBC
:
272 c
= SMIME_AES_CBC_192
;
274 case SEC_OID_AES_256_CBC
:
275 c
= SMIME_AES_CBC_256
;
285 nss_smime_cipher_allowed(unsigned long which
)
289 mapi
= smime_mapi_by_cipher(which
);
292 return smime_cipher_map
[mapi
].allowed
;
296 SecSMIMEDecryptionAllowed(SECAlgorithmID
*algid
, SecSymmetricKeyRef key
)
300 if (nss_smime_get_cipher_for_alg_and_key(algid
, key
, &which
) != SECSuccess
)
303 return nss_smime_cipher_allowed(which
);
308 * NSS_SMIME_EncryptionPossible - check if any encryption is allowed
310 * This tells whether or not *any* S/MIME encryption can be done,
311 * according to policy. Callers may use this to do nicer user interface
312 * (say, greying out a checkbox so a user does not even try to encrypt
313 * a message when they are not allowed to) or for any reason they want
314 * to check whether S/MIME encryption (or decryption, for that matter)
317 * It takes no arguments. The return value is a simple boolean:
318 * PR_TRUE means encryption (or decryption) is *possible*
319 * (but may still fail due to other reasons, like because we cannot
320 * find all the necessary certs, etc.; PR_TRUE is *not* a guarantee)
321 * PR_FALSE means encryption (or decryption) is not permitted
323 * There are no errors from this routine.
326 SecSMIMEEncryptionPossible(void)
330 for (i
= 0; i
< smime_cipher_map_count
; i
++) {
331 if (smime_cipher_map
[i
].allowed
)
339 nss_SMIME_FindCipherForSMIMECap(NSSSMIMECapability
*cap
)
344 /* we need the OIDTag here */
345 capIDTag
= SECOID_FindOIDTag(&(cap
->capabilityID
));
347 /* go over all the SMIME ciphers we know and see if we find a match */
348 for (i
= 0; i
< smime_cipher_map_count
; i
++) {
349 if (smime_cipher_map
[i
].algtag
!= capIDTag
)
352 * XXX If SECITEM_CompareItem allowed NULLs as arguments (comparing
353 * 2 NULLs as equal and NULL and non-NULL as not equal), we could
354 * use that here instead of all of the following comparison code.
356 if (cap
->parameters
.Data
== NULL
&& smime_cipher_map
[i
].parms
== NULL
)
357 break; /* both empty: bingo */
359 if (cap
->parameters
.Data
!= NULL
&& smime_cipher_map
[i
].parms
!= NULL
&&
360 cap
->parameters
.Length
== smime_cipher_map
[i
].parms
->Length
&&
361 PORT_Memcmp (cap
->parameters
.Data
, smime_cipher_map
[i
].parms
->Data
,
362 cap
->parameters
.Length
) == 0)
364 break; /* both not empty, same length & equal content: bingo */
368 if (i
== smime_cipher_map_count
)
369 return 0; /* no match found */
371 return smime_cipher_map
[i
].cipher
; /* match found, point to cipher */
374 static int smime_keysize_by_cipher (unsigned long which
);
377 * smime_choose_cipher - choose a cipher that works for all the recipients
379 * "scert" - sender's certificate
380 * "rcerts" - recipient's certificates
383 smime_choose_cipher(SecCertificateRef scert
, SecCertificateRef
*rcerts
)
388 int *cipher_abilities
;
392 int rcount
, mapi
, max
, i
;
394 // @@@ We Don't support Fortezza yet.
395 Boolean scert_is_fortezza
= PR_FALSE
;
397 Boolean scert_is_fortezza
= (scert
== NULL
) ? PR_FALSE
: PK11_FortezzaHasKEA(scert
);
400 chosen_cipher
= SMIME_DES_CBC_56
; /* the default, LCD */
401 weak_mapi
= smime_mapi_by_cipher(chosen_cipher
);
403 poolp
= PORT_NewArena (1024); /* XXX what is right value? */
407 cipher_abilities
= (int *)PORT_ArenaZAlloc(poolp
, smime_cipher_map_count
* sizeof(int));
408 cipher_votes
= (int *)PORT_ArenaZAlloc(poolp
, smime_cipher_map_count
* sizeof(int));
409 if (cipher_votes
== NULL
|| cipher_abilities
== NULL
)
412 /* If the user has the Fortezza preference turned on, make
413 * that the strong cipher. Otherwise, use triple-DES. */
414 strong_mapi
= smime_mapi_by_cipher (SMIME_DES_EDE3_168
);
415 if (scert_is_fortezza
) {
416 mapi
= smime_mapi_by_cipher(SMIME_FORTEZZA
);
417 if (mapi
>= 0 && smime_cipher_map
[mapi
].enabled
)
421 /* walk all the recipient's certs */
422 for (rcount
= 0; rcerts
[rcount
] != NULL
; rcount
++) {
423 SecAsn1Item
*profile
;
424 NSSSMIMECapability
**caps
;
427 /* the first cipher that matches in the user's SMIME profile gets
428 * "smime_cipher_map_count" votes; the next one gets "smime_cipher_map_count" - 1
429 * and so on. If every cipher matches, the last one gets 1 (one) vote */
430 pref
= smime_cipher_map_count
;
432 /* find recipient's SMIME profile */
433 profile
= CERT_FindSMimeProfile(rcerts
[rcount
]);
435 if (profile
!= NULL
&& profile
->Data
!= NULL
&& profile
->Length
> 0) {
436 /* we have a profile (still DER-encoded) */
439 if (SEC_ASN1DecodeItem(poolp
, &caps
, NSSSMIMECapabilitiesTemplate
, profile
) == SECSuccess
&&
442 /* walk the SMIME capabilities for this recipient */
443 for (i
= 0; caps
[i
] != NULL
; i
++) {
444 cipher
= nss_SMIME_FindCipherForSMIMECap(caps
[i
]);
445 mapi
= smime_mapi_by_cipher(cipher
);
447 /* found the cipher */
448 cipher_abilities
[mapi
]++;
449 cipher_votes
[mapi
] += pref
;
455 /* no profile found - so we can only assume that the user can do
456 * the mandatory algorithms which is RC2-40 (weak crypto) and 3DES (strong crypto) */
461 * if recipient's public key length is > 512, vote for a strong cipher
462 * please not that the side effect of this is that if only one recipient
463 * has an export-level public key, the strong cipher is disabled.
465 * XXX This is probably only good for RSA keys. What I would
466 * really like is a function to just say; Is the public key in
467 * this cert an export-length key? Then I would not have to
468 * know things like the value 512, or the kind of key, or what
469 * a subjectPublicKeyInfo is, etc.
471 key
= CERT_ExtractPublicKey(rcerts
[rcount
]);
474 pklen_bits
= SecKeyGetSize(key
, kSecKeyKeySizeInBits
);
475 SECKEY_DestroyPublicKey (key
);
478 if (pklen_bits
> 512) {
479 /* cast votes for the strong algorithm */
480 cipher_abilities
[strong_mapi
]++;
481 cipher_votes
[strong_mapi
] += pref
;
485 /* always cast (possibly less) votes for the weak algorithm */
486 cipher_abilities
[weak_mapi
]++;
487 cipher_votes
[weak_mapi
] += pref
;
490 SECITEM_FreeItem(profile
, PR_TRUE
);
493 /* find cipher that is agreeable by all recipients and that has the most votes */
495 for (mapi
= 0; mapi
< smime_cipher_map_count
; mapi
++) {
496 /* if not all of the recipients can do this, forget it */
497 if (cipher_abilities
[mapi
] != rcount
)
499 /* if cipher is not enabled or not allowed by policy, forget it */
500 if (!smime_cipher_map
[mapi
].enabled
|| !smime_cipher_map
[mapi
].allowed
)
502 /* if we're not doing fortezza, but the cipher is fortezza, forget it */
503 if (!scert_is_fortezza
&& (smime_cipher_map
[mapi
].cipher
== SMIME_FORTEZZA
))
505 /* now see if this one has more votes than the last best one */
506 if (cipher_votes
[mapi
] >= max
) {
507 /* if equal number of votes, prefer the ones further down in the list */
508 /* with the expectation that these are higher rated ciphers */
509 chosen_cipher
= smime_cipher_map
[mapi
].cipher
;
510 max
= cipher_votes
[mapi
];
513 /* if no common cipher was found, chosen_cipher stays at the default */
517 PORT_FreeArena (poolp
, PR_FALSE
);
519 if (smime_keysize_by_cipher(chosen_cipher
) < 128) {
520 /* you're going to use strong(er) crypto whether you like it or not */
521 chosen_cipher
= SMIME_DES_EDE3_168
;
523 return chosen_cipher
;
527 * XXX This is a hack for now to satisfy our current interface.
528 * Eventually, with more parameters needing to be specified, just
529 * looking up the keysize is not going to be sufficient.
532 smime_keysize_by_cipher (unsigned long which
)
537 case SMIME_RC2_CBC_40
:
540 case SMIME_RC2_CBC_64
:
543 case SMIME_RC2_CBC_128
:
546 case SMIME_DES_CBC_56
:
549 case SMIME_DES_EDE3_168
:
554 * This is special; since the key size is fixed, we actually
555 * want to *avoid* specifying a key size.
568 * SecSMIMEFindBulkAlgForRecipients - find bulk algorithm suitable for all recipients
570 * it would be great for UI purposes if there would be a way to find out which recipients
571 * prevented a strong cipher from being used...
574 SecSMIMEFindBulkAlgForRecipients(SecCertificateRef
*rcerts
, SECOidTag
*bulkalgtag
, int *keysize
)
576 unsigned long cipher
;
579 cipher
= smime_choose_cipher(NULL
, rcerts
);
580 mapi
= smime_mapi_by_cipher(cipher
);
585 *bulkalgtag
= smime_cipher_map
[mapi
].algtag
;
586 *keysize
= smime_keysize_by_cipher(smime_cipher_map
[mapi
].cipher
);
592 * SecSMIMECreateSMIMECapabilities - get S/MIME capabilities for this instance of NSS
594 * scans the list of allowed and enabled ciphers and construct a PKCS9-compliant
595 * S/MIME capabilities attribute value.
597 * XXX Please note that, in contradiction to RFC2633 2.5.2, the capabilities only include
598 * symmetric ciphers, NO signature algorithms or key encipherment algorithms.
600 * "poolp" - arena pool to create the S/MIME capabilities data on
601 * "dest" - SecAsn1Item to put the data in
602 * "includeFortezzaCiphers" - PR_TRUE if fortezza ciphers should be included
605 SecSMIMECreateSMIMECapabilities(PLArenaPool
*poolp
, SecAsn1Item
*dest
, Boolean includeFortezzaCiphers
)
607 NSSSMIMECapability
*cap
;
608 NSSSMIMECapability
**smime_capabilities
;
609 smime_cipher_map_entry
*map
;
614 /* if we have an old NSSSMIMECapability array, we'll reuse it (has the right size) */
615 /* smime_cipher_map_count + 1 is an upper bound - we might end up with less */
616 smime_capabilities
= (NSSSMIMECapability
**)PORT_ZAlloc((smime_cipher_map_count
+ 1)
617 * sizeof(NSSSMIMECapability
*));
618 if (smime_capabilities
== NULL
)
623 /* Add all the symmetric ciphers
624 * We walk the cipher list backwards, as it is ordered by increasing strength,
625 * we prefer the stronger cipher over a weaker one, and we have to list the
626 * preferred algorithm first */
627 for (i
= smime_cipher_map_count
- 1; i
>= 0; i
--) {
628 /* Find the corresponding entry in the cipher map. */
629 map
= &(smime_cipher_map
[i
]);
633 /* If we're using a non-Fortezza cert, only advertise non-Fortezza
634 capabilities. (We advertise all capabilities if we have a
636 if ((!includeFortezzaCiphers
) && (map
->cipher
== SMIME_FORTEZZA
))
639 /* get next SMIME capability */
640 cap
= (NSSSMIMECapability
*)PORT_ZAlloc(sizeof(NSSSMIMECapability
));
643 smime_capabilities
[capIndex
++] = cap
;
645 oiddata
= SECOID_FindOIDByTag(map
->algtag
);
649 cap
->capabilityID
.Data
= oiddata
->oid
.Data
;
650 cap
->capabilityID
.Length
= oiddata
->oid
.Length
;
651 cap
->parameters
.Data
= map
->parms
? map
->parms
->Data
: NULL
;
652 cap
->parameters
.Length
= map
->parms
? map
->parms
->Length
: 0;
653 cap
->cipher
= smime_cipher_map
[i
].cipher
;
656 /* XXX add signature algorithms */
657 /* XXX add key encipherment algorithms */
659 smime_capabilities
[capIndex
] = NULL
; /* last one - now encode */
660 dummy
= SEC_ASN1EncodeItem(poolp
, dest
, &smime_capabilities
, NSSSMIMECapabilitiesTemplate
);
662 /* now that we have the proper encoded SMIMECapabilities (or not),
663 * free the work data */
664 for (i
= 0; smime_capabilities
[i
] != NULL
; i
++)
665 PORT_Free(smime_capabilities
[i
]);
666 PORT_Free(smime_capabilities
);
668 return (dummy
== NULL
) ? SECFailure
: SECSuccess
;
672 * SecSMIMECreateSMIMEEncKeyPrefs - create S/MIME encryption key preferences attr value
674 * "poolp" - arena pool to create the attr value on
675 * "dest" - SecAsn1Item to put the data in
676 * "cert" - certificate that should be marked as preferred encryption key
677 * cert is expected to have been verified for EmailRecipient usage.
680 SecSMIMECreateSMIMEEncKeyPrefs(PLArenaPool
*poolp
, SecAsn1Item
*dest
, SecCertificateRef cert
)
682 NSSSMIMEEncryptionKeyPreference ekp
;
683 SecAsn1Item
*dummy
= NULL
;
684 PLArenaPool
*tmppoolp
= NULL
;
689 tmppoolp
= PORT_NewArena(1024);
690 if (tmppoolp
== NULL
)
693 /* XXX hardcoded IssuerSN choice for now */
694 ekp
.selector
= NSSSMIMEEncryptionKeyPref_IssuerSN
;
695 ekp
.id
.issuerAndSN
= CERT_GetCertIssuerAndSN(tmppoolp
, cert
);
696 if (ekp
.id
.issuerAndSN
== NULL
)
699 dummy
= SEC_ASN1EncodeItem(poolp
, dest
, &ekp
, smime_encryptionkeypref_template
);
702 if (tmppoolp
) PORT_FreeArena(tmppoolp
, PR_FALSE
);
704 return (dummy
== NULL
) ? SECFailure
: SECSuccess
;
708 * SecSMIMECreateSMIMEEncKeyPrefs - create S/MIME encryption key preferences attr value using MS oid
710 * "poolp" - arena pool to create the attr value on
711 * "dest" - SecAsn1Item to put the data in
712 * "cert" - certificate that should be marked as preferred encryption key
713 * cert is expected to have been verified for EmailRecipient usage.
716 SecSMIMECreateMSSMIMEEncKeyPrefs(PLArenaPool
*poolp
, SecAsn1Item
*dest
, SecCertificateRef cert
)
718 SecAsn1Item
*dummy
= NULL
;
719 PLArenaPool
*tmppoolp
= NULL
;
720 SecCmsIssuerAndSN
*isn
;
725 tmppoolp
= PORT_NewArena(1024);
726 if (tmppoolp
== NULL
)
729 isn
= CERT_GetCertIssuerAndSN(tmppoolp
, cert
);
733 dummy
= SEC_ASN1EncodeItem(poolp
, dest
, isn
, SEC_ASN1_GET(SecCmsIssuerAndSNTemplate
));
736 if (tmppoolp
) PORT_FreeArena(tmppoolp
, PR_FALSE
);
738 return (dummy
== NULL
) ? SECFailure
: SECSuccess
;
743 * SecSMIMEGetCertFromEncryptionKeyPreference -
744 * find cert marked by EncryptionKeyPreference attribute
746 * "keychainOrArray" - handle for the cert database to look in
747 * "DERekp" - DER-encoded value of S/MIME Encryption Key Preference attribute
749 * if certificate is supposed to be found among the message's included certificates,
750 * they are assumed to have been imported already.
753 SecSMIMEGetCertFromEncryptionKeyPreference(SecKeychainRef keychainOrArray
, SecAsn1Item
*DERekp
)
755 PLArenaPool
*tmppoolp
= NULL
;
756 SecCertificateRef cert
= NULL
;
757 NSSSMIMEEncryptionKeyPreference ekp
;
759 tmppoolp
= PORT_NewArena(1024);
760 if (tmppoolp
== NULL
)
764 if (SEC_ASN1DecodeItem(tmppoolp
, &ekp
, smime_encryptionkeypref_template
, DERekp
) != SECSuccess
)
768 switch (ekp
.selector
) {
769 case NSSSMIMEEncryptionKeyPref_IssuerSN
:
770 cert
= CERT_FindCertByIssuerAndSN(keychainOrArray
, ekp
.id
.issuerAndSN
);
772 case NSSSMIMEEncryptionKeyPref_RKeyID
:
773 case NSSSMIMEEncryptionKeyPref_SubjectKeyID
:
774 /* XXX not supported yet - we need to be able to look up certs by SubjectKeyID */
780 if (tmppoolp
) PORT_FreeArena(tmppoolp
, PR_FALSE
);
787 extern const char __nss_smime_rcsid
[];
788 extern const char __nss_smime_sccsid
[];
791 NSSSMIME_VersionCheck(const char *importedVersion
)
797 * This is the secret handshake algorithm.
799 * This release has a simple version compatibility
800 * check algorithm. This release is not backward
801 * compatible with previous major releases. It is
802 * not compatible with future major, minor, or
805 volatile char c
; /* force a reference that won't get optimized away */
807 c
= __nss_smime_rcsid
[0] + __nss_smime_sccsid
[0];
809 return NSS_VersionCheck(importedVersion
);