openssl.txt 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254
  1. This is some preliminary documentation for OpenSSL.
  2. Contents:
  3. OpenSSL X509V3 extension configuration
  4. X509V3 Extension code: programmers guide
  5. PKCS#12 Library
  6. ==============================================================================
  7. OpenSSL X509V3 extension configuration
  8. ==============================================================================
  9. OpenSSL X509V3 extension configuration: preliminary documentation.
  10. INTRODUCTION.
  11. For OpenSSL 0.9.2 the extension code has be considerably enhanced. It is now
  12. possible to add and print out common X509 V3 certificate and CRL extensions.
  13. BEGINNERS NOTE
  14. For most simple applications you don't need to know too much about extensions:
  15. the default openssl.cnf values will usually do sensible things.
  16. If you want to know more you can initially quickly look through the sections
  17. describing how the standard OpenSSL utilities display and add extensions and
  18. then the list of supported extensions.
  19. For more technical information about the meaning of extensions see:
  20. http://www.imc.org/ietf-pkix/
  21. http://home.netscape.com/eng/security/certs.html
  22. PRINTING EXTENSIONS.
  23. Extension values are automatically printed out for supported extensions.
  24. openssl x509 -in cert.pem -text
  25. openssl crl -in crl.pem -text
  26. will give information in the extension printout, for example:
  27. X509v3 extensions:
  28. X509v3 Basic Constraints:
  29. CA:TRUE
  30. X509v3 Subject Key Identifier:
  31. 73:FE:F7:59:A7:E1:26:84:44:D6:44:36:EE:79:1A:95:7C:B1:4B:15
  32. X509v3 Authority Key Identifier:
  33. keyid:73:FE:F7:59:A7:E1:26:84:44:D6:44:36:EE:79:1A:95:7C:B1:4B:15, DirName:/C=AU/ST=Some-State/O=Internet Widgits Pty Ltd/Email=email@1.address/Email=email@2.address, serial:00
  34. X509v3 Key Usage:
  35. Certificate Sign, CRL Sign
  36. X509v3 Subject Alternative Name:
  37. email:email@1.address, email:email@2.address
  38. CONFIGURATION FILES.
  39. The OpenSSL utilities 'ca' and 'req' can now have extension sections listing
  40. which certificate extensions to include. In each case a line:
  41. x509_extensions = extension_section
  42. indicates which section contains the extensions. In the case of 'req' the
  43. extension section is used when the -x509 option is present to create a
  44. self signed root certificate.
  45. The 'x509' utility also supports extensions when it signs a certificate.
  46. The -extfile option is used to set the configuration file containing the
  47. extensions. In this case a line with:
  48. extensions = extension_section
  49. in the nameless (default) section is used. If no such line is included then
  50. it uses the default section.
  51. You can also add extensions to CRLs: a line
  52. crl_extensions = crl_extension_section
  53. will include extensions when the -gencrl option is used with the 'ca' utility.
  54. You can add any extension to a CRL but of the supported extensions only
  55. issuerAltName and authorityKeyIdentifier make any real sense. Note: these are
  56. CRL extensions NOT CRL *entry* extensions which cannot currently be generated.
  57. CRL entry extensions can be displayed.
  58. NB. At this time Netscape Communicator rejects V2 CRLs: to get an old V1 CRL
  59. you should not include a crl_extensions line in the configuration file.
  60. As with all configuration files you can use the inbuilt environment expansion
  61. to allow the values to be passed in the environment. Therefore if you have
  62. several extension sections used for different purposes you can have a line:
  63. x509_extensions = $ENV::ENV_EXT
  64. and set the ENV_EXT environment variable before calling the relevant utility.
  65. EXTENSION SYNTAX.
  66. Extensions have the basic form:
  67. extension_name=[critical,] extension_options
  68. the use of the critical option makes the extension critical. Extreme caution
  69. should be made when using the critical flag. If an extension is marked
  70. as critical then any client that does not understand the extension should
  71. reject it as invalid. Some broken software will reject certificates which
  72. have *any* critical extensions (these violates PKIX but we have to live
  73. with it).
  74. There are three main types of extension: string extensions, multi-valued
  75. extensions, and raw extensions.
  76. String extensions simply have a string which contains either the value itself
  77. or how it is obtained.
  78. For example:
  79. nsComment="This is a Comment"
  80. Multi-valued extensions have a short form and a long form. The short form
  81. is a list of names and values:
  82. basicConstraints=critical,CA:true,pathlen:1
  83. The long form allows the values to be placed in a separate section:
  84. basicConstraints=critical,@bs_section
  85. [bs_section]
  86. CA=true
  87. pathlen=1
  88. Both forms are equivalent. However it should be noted that in some cases the
  89. same name can appear multiple times, for example,
  90. subjectAltName=email:steve@here,email:steve@there
  91. in this case an equivalent long form is:
  92. subjectAltName=@alt_section
  93. [alt_section]
  94. email.1=steve@here
  95. email.2=steve@there
  96. This is because the configuration file code cannot handle the same name
  97. occurring twice in the same section.
  98. The syntax of raw extensions is governed by the extension code: it can
  99. for example contain data in multiple sections. The correct syntax to
  100. use is defined by the extension code itself: check out the certificate
  101. policies extension for an example.
  102. There are two ways to encode arbitrary extensions.
  103. The first way is to use the word ASN1 followed by the extension content
  104. using the same syntax as ASN1_generate_nconf(). For example:
  105. 1.2.3.4=critical,ASN1:UTF8String:Some random data
  106. 1.2.3.4=ASN1:SEQUENCE:seq_sect
  107. [seq_sect]
  108. field1 = UTF8:field1
  109. field2 = UTF8:field2
  110. It is also possible to use the word DER to include arbitrary data in any
  111. extension.
  112. 1.2.3.4=critical,DER:01:02:03:04
  113. 1.2.3.4=DER:01020304
  114. The value following DER is a hex dump of the DER encoding of the extension
  115. Any extension can be placed in this form to override the default behaviour.
  116. For example:
  117. basicConstraints=critical,DER:00:01:02:03
  118. WARNING: DER should be used with caution. It is possible to create totally
  119. invalid extensions unless care is taken.
  120. CURRENTLY SUPPORTED EXTENSIONS.
  121. If you aren't sure about extensions then they can be largely ignored: its only
  122. when you want to do things like restrict certificate usage when you need to
  123. worry about them.
  124. The only extension that a beginner might want to look at is Basic Constraints.
  125. If in addition you want to try Netscape object signing the you should also
  126. look at Netscape Certificate Type.
  127. Literal String extensions.
  128. In each case the 'value' of the extension is placed directly in the
  129. extension. Currently supported extensions in this category are: nsBaseUrl,
  130. nsRevocationUrl, nsCaRevocationUrl, nsRenewalUrl, nsCaPolicyUrl,
  131. nsSslServerName and nsComment.
  132. For example:
  133. nsComment="This is a test comment"
  134. Bit Strings.
  135. Bit string extensions just consist of a list of supported bits, currently
  136. two extensions are in this category: PKIX keyUsage and the Netscape specific
  137. nsCertType.
  138. nsCertType (netscape certificate type) takes the flags: client, server, email,
  139. objsign, reserved, sslCA, emailCA, objCA.
  140. keyUsage (PKIX key usage) takes the flags: digitalSignature, nonRepudiation,
  141. keyEncipherment, dataEncipherment, keyAgreement, keyCertSign, cRLSign,
  142. encipherOnly, decipherOnly.
  143. For example:
  144. nsCertType=server
  145. keyUsage=digitalSignature, nonRepudiation
  146. Hints on Netscape Certificate Type.
  147. Other than Basic Constraints this is the only extension a beginner might
  148. want to use, if you want to try Netscape object signing, otherwise it can
  149. be ignored.
  150. If you want a certificate that can be used just for object signing then:
  151. nsCertType=objsign
  152. will do the job. If you want to use it as a normal end user and server
  153. certificate as well then
  154. nsCertType=objsign,email,server
  155. is more appropriate. You cannot use a self signed certificate for object
  156. signing (well Netscape signtool can but it cheats!) so you need to create
  157. a CA certificate and sign an end user certificate with it.
  158. Side note: If you want to conform to the Netscape specifications then you
  159. should really also set:
  160. nsCertType=objCA
  161. in the *CA* certificate for just an object signing CA and
  162. nsCertType=objCA,emailCA,sslCA
  163. for everything. Current Netscape software doesn't enforce this so it can
  164. be omitted.
  165. Basic Constraints.
  166. This is generally the only extension you need to worry about for simple
  167. applications. If you want your certificate to be usable as a CA certificate
  168. (in addition to an end user certificate) then you set this to:
  169. basicConstraints=CA:TRUE
  170. if you want to be certain the certificate cannot be used as a CA then do:
  171. basicConstraints=CA:FALSE
  172. The rest of this section describes more advanced usage.
  173. Basic constraints is a multi-valued extension that supports a CA and an
  174. optional pathlen option. The CA option takes the values true and false and
  175. pathlen takes an integer. Note if the CA option is false the pathlen option
  176. should be omitted.
  177. The pathlen parameter indicates the maximum number of CAs that can appear
  178. below this one in a chain. So if you have a CA with a pathlen of zero it can
  179. only be used to sign end user certificates and not further CAs. This all
  180. assumes that the software correctly interprets this extension of course.
  181. Examples:
  182. basicConstraints=CA:TRUE
  183. basicConstraints=critical,CA:TRUE, pathlen:0
  184. NOTE: for a CA to be considered valid it must have the CA option set to
  185. TRUE. An end user certificate MUST NOT have the CA value set to true.
  186. According to PKIX recommendations it should exclude the extension entirely,
  187. however some software may require CA set to FALSE for end entity certificates.
  188. Extended Key Usage.
  189. This extensions consists of a list of usages.
  190. These can either be object short names of the dotted numerical form of OIDs.
  191. While any OID can be used only certain values make sense. In particular the
  192. following PKIX, NS and MS values are meaningful:
  193. Value Meaning
  194. ----- -------
  195. serverAuth SSL/TLS Web Server Authentication.
  196. clientAuth SSL/TLS Web Client Authentication.
  197. codeSigning Code signing.
  198. emailProtection E-mail Protection (S/MIME).
  199. timeStamping Trusted Timestamping
  200. msCodeInd Microsoft Individual Code Signing (authenticode)
  201. msCodeCom Microsoft Commercial Code Signing (authenticode)
  202. msCTLSign Microsoft Trust List Signing
  203. msSGC Microsoft Server Gated Crypto
  204. msEFS Microsoft Encrypted File System
  205. nsSGC Netscape Server Gated Crypto
  206. For example, under IE5 a CA can be used for any purpose: by including a list
  207. of the above usages the CA can be restricted to only authorised uses.
  208. Note: software packages may place additional interpretations on certificate
  209. use, in particular some usages may only work for selected CAs. Don't for example
  210. expect just including msSGC or nsSGC will automatically mean that a certificate
  211. can be used for SGC ("step up" encryption) otherwise anyone could use it.
  212. Examples:
  213. extendedKeyUsage=critical,codeSigning,1.2.3.4
  214. extendedKeyUsage=nsSGC,msSGC
  215. Subject Key Identifier.
  216. This is really a string extension and can take two possible values. Either
  217. a hex string giving details of the extension value to include or the word
  218. 'hash' which then automatically follow PKIX guidelines in selecting and
  219. appropriate key identifier. The use of the hex string is strongly discouraged.
  220. Example: subjectKeyIdentifier=hash
  221. Authority Key Identifier.
  222. The authority key identifier extension permits two options. keyid and issuer:
  223. both can take the optional value "always".
  224. If the keyid option is present an attempt is made to copy the subject key
  225. identifier from the parent certificate. If the value "always" is present
  226. then an error is returned if the option fails.
  227. The issuer option copies the issuer and serial number from the issuer
  228. certificate. Normally this will only be done if the keyid option fails or
  229. is not included: the "always" flag will always include the value.
  230. Subject Alternative Name.
  231. The subject alternative name extension allows various literal values to be
  232. included in the configuration file. These include "email" (an email address)
  233. "URI" a uniform resource indicator, "DNS" (a DNS domain name), RID (a
  234. registered ID: OBJECT IDENTIFIER), IP (and IP address) and otherName.
  235. Also the email option include a special 'copy' value. This will automatically
  236. include and email addresses contained in the certificate subject name in
  237. the extension.
  238. otherName can include arbitrary data associated with an OID: the value
  239. should be the OID followed by a semicolon and the content in standard
  240. ASN1_generate_nconf() format.
  241. Examples:
  242. subjectAltName=email:copy,email:my@other.address,URI:http://my.url.here/
  243. subjectAltName=email:my@other.address,RID:1.2.3.4
  244. subjectAltName=otherName:1.2.3.4;UTF8:some other identifier
  245. Issuer Alternative Name.
  246. The issuer alternative name option supports all the literal options of
  247. subject alternative name. It does *not* support the email:copy option because
  248. that would not make sense. It does support an additional issuer:copy option
  249. that will copy all the subject alternative name values from the issuer
  250. certificate (if possible).
  251. Example:
  252. issuserAltName = issuer:copy
  253. Authority Info Access.
  254. The authority information access extension gives details about how to access
  255. certain information relating to the CA. Its syntax is accessOID;location
  256. where 'location' has the same syntax as subject alternative name (except
  257. that email:copy is not supported). accessOID can be any valid OID but only
  258. certain values are meaningful for example OCSP and caIssuers. OCSP gives the
  259. location of an OCSP responder: this is used by Netscape PSM and other software.
  260. Example:
  261. authorityInfoAccess = OCSP;URI:http://ocsp.my.host/
  262. authorityInfoAccess = caIssuers;URI:http://my.ca/ca.html
  263. CRL distribution points.
  264. This is a multi-valued extension that supports all the literal options of
  265. subject alternative name. Of the few software packages that currently interpret
  266. this extension most only interpret the URI option.
  267. Currently each option will set a new DistributionPoint with the fullName
  268. field set to the given value.
  269. Other fields like cRLissuer and reasons cannot currently be set or displayed:
  270. at this time no examples were available that used these fields.
  271. If you see this extension with <UNSUPPORTED> when you attempt to print it out
  272. or it doesn't appear to display correctly then let me know, including the
  273. certificate (mail me at steve@openssl.org) .
  274. Examples:
  275. crlDistributionPoints=URI:http://www.myhost.com/myca.crl
  276. crlDistributionPoints=URI:http://www.my.com/my.crl,URI:http://www.oth.com/my.crl
  277. Certificate Policies.
  278. This is a RAW extension. It attempts to display the contents of this extension:
  279. unfortunately this extension is often improperly encoded.
  280. The certificate policies extension will rarely be used in practice: few
  281. software packages interpret it correctly or at all. IE5 does partially
  282. support this extension: but it needs the 'ia5org' option because it will
  283. only correctly support a broken encoding. Of the options below only the
  284. policy OID, explicitText and CPS options are displayed with IE5.
  285. All the fields of this extension can be set by using the appropriate syntax.
  286. If you follow the PKIX recommendations of not including any qualifiers and just
  287. using only one OID then you just include the value of that OID. Multiple OIDs
  288. can be set separated by commas, for example:
  289. certificatePolicies= 1.2.4.5, 1.1.3.4
  290. If you wish to include qualifiers then the policy OID and qualifiers need to
  291. be specified in a separate section: this is done by using the @section syntax
  292. instead of a literal OID value.
  293. The section referred to must include the policy OID using the name
  294. policyIdentifier, cPSuri qualifiers can be included using the syntax:
  295. CPS.nnn=value
  296. userNotice qualifiers can be set using the syntax:
  297. userNotice.nnn=@notice
  298. The value of the userNotice qualifier is specified in the relevant section.
  299. This section can include explicitText, organization and noticeNumbers
  300. options. explicitText and organization are text strings, noticeNumbers is a
  301. comma separated list of numbers. The organization and noticeNumbers options
  302. (if included) must BOTH be present. If you use the userNotice option with IE5
  303. then you need the 'ia5org' option at the top level to modify the encoding:
  304. otherwise it will not be interpreted properly.
  305. Example:
  306. certificatePolicies=ia5org,1.2.3.4,1.5.6.7.8,@polsect
  307. [polsect]
  308. policyIdentifier = 1.3.5.8
  309. CPS.1="http://my.host.name/"
  310. CPS.2="http://my.your.name/"
  311. userNotice.1=@notice
  312. [notice]
  313. explicitText="Explicit Text Here"
  314. organization="Organisation Name"
  315. noticeNumbers=1,2,3,4
  316. TECHNICAL NOTE: the ia5org option changes the type of the 'organization' field,
  317. according to PKIX it should be of type DisplayText but Verisign uses an
  318. IA5STRING and IE5 needs this too.
  319. Display only extensions.
  320. Some extensions are only partially supported and currently are only displayed
  321. but cannot be set. These include private key usage period, CRL number, and
  322. CRL reason.
  323. ==============================================================================
  324. X509V3 Extension code: programmers guide
  325. ==============================================================================
  326. The purpose of the extension code is twofold. It allows an extension to be
  327. created from a string or structure describing its contents and it prints out an
  328. extension in a human or machine readable form.
  329. 1. Initialisation and cleanup.
  330. No special initialisation is needed before calling the extension functions.
  331. You used to have to call X509V3_add_standard_extensions(); but this is no longer
  332. required and this function no longer does anything.
  333. void X509V3_EXT_cleanup(void);
  334. This function should be called to cleanup the extension code if any custom
  335. extensions have been added. If no custom extensions have been added then this
  336. call does nothing. After this call all custom extension code is freed up but
  337. you can still use the standard extensions.
  338. 2. Printing and parsing extensions.
  339. The simplest way to print out extensions is via the standard X509 printing
  340. routines: if you use the standard X509_print() function, the supported
  341. extensions will be printed out automatically.
  342. The following functions allow finer control over extension display:
  343. int X509V3_EXT_print(BIO *out, X509_EXTENSION *ext, int flag, int indent);
  344. int X509V3_EXT_print_fp(FILE *out, X509_EXTENSION *ext, int flag, int indent);
  345. These two functions print out an individual extension to a BIO or FILE pointer.
  346. Currently the flag argument is unused and should be set to 0. The 'indent'
  347. argument is the number of spaces to indent each line.
  348. void *X509V3_EXT_d2i(X509_EXTENSION *ext);
  349. This function parses an extension and returns its internal structure. The
  350. precise structure you get back depends on the extension being parsed. If the
  351. extension if basicConstraints you will get back a pointer to a
  352. BASIC_CONSTRAINTS structure. Check out the source in crypto/x509v3 for more
  353. details about the structures returned. The returned structure should be freed
  354. after use using the relevant free function, BASIC_CONSTRAINTS_free() for
  355. example.
  356. void * X509_get_ext_d2i(X509 *x, int nid, int *crit, int *idx);
  357. void * X509_CRL_get_ext_d2i(X509_CRL *x, int nid, int *crit, int *idx);
  358. void * X509_REVOKED_get_ext_d2i(X509_REVOKED *x, int nid, int *crit, int *idx);
  359. void * X509V3_get_d2i(STACK_OF(X509_EXTENSION) *x, int nid, int *crit, int *idx);
  360. These functions combine the operations of searching for extensions and
  361. parsing them. They search a certificate, a CRL a CRL entry or a stack
  362. of extensions respectively for extension whose NID is 'nid' and return
  363. the parsed result of NULL if an error occurred. For example:
  364. BASIC_CONSTRAINTS *bs;
  365. bs = X509_get_ext_d2i(cert, NID_basic_constraints, NULL, NULL);
  366. This will search for the basicConstraints extension and either return
  367. it value or NULL. NULL can mean either the extension was not found, it
  368. occurred more than once or it could not be parsed.
  369. If 'idx' is NULL then an extension is only parsed if it occurs precisely
  370. once. This is standard behaviour because extensions normally cannot occur
  371. more than once. If however more than one extension of the same type can
  372. occur it can be used to parse successive extensions for example:
  373. int i;
  374. void *ext;
  375. i = -1;
  376. for(;;) {
  377. ext = X509_get_ext_d2i(x, nid, crit, &idx);
  378. if(ext == NULL) break;
  379. /* Do something with ext */
  380. }
  381. If 'crit' is not NULL and the extension was found then the int it points to
  382. is set to 1 for critical extensions and 0 for non critical. Therefore if the
  383. function returns NULL but 'crit' is set to 0 or 1 then the extension was
  384. found but it could not be parsed.
  385. The int pointed to by crit will be set to -1 if the extension was not found
  386. and -2 if the extension occurred more than once (this will only happen if
  387. idx is NULL). In both cases the function will return NULL.
  388. 3. Generating extensions.
  389. An extension will typically be generated from a configuration file, or some
  390. other kind of configuration database.
  391. int X509V3_EXT_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section,
  392. X509 *cert);
  393. int X509V3_EXT_CRL_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section,
  394. X509_CRL *crl);
  395. These functions add all the extensions in the given section to the given
  396. certificate or CRL. They will normally be called just before the certificate
  397. or CRL is due to be signed. Both return 0 on error on non zero for success.
  398. In each case 'conf' is the LHASH pointer of the configuration file to use
  399. and 'section' is the section containing the extension details.
  400. See the 'context functions' section for a description of the ctx parameter.
  401. X509_EXTENSION *X509V3_EXT_conf(LHASH *conf, X509V3_CTX *ctx, char *name,
  402. char *value);
  403. This function returns an extension based on a name and value pair, if the
  404. pair will not need to access other sections in a config file (or there is no
  405. config file) then the 'conf' parameter can be set to NULL.
  406. X509_EXTENSION *X509V3_EXT_conf_nid(char *conf, X509V3_CTX *ctx, int nid,
  407. char *value);
  408. This function creates an extension in the same way as X509V3_EXT_conf() but
  409. takes the NID of the extension rather than its name.
  410. For example to produce basicConstraints with the CA flag and a path length of
  411. 10:
  412. x = X509V3_EXT_conf_nid(NULL, NULL, NID_basic_constraints,"CA:TRUE,pathlen:10");
  413. X509_EXTENSION *X509V3_EXT_i2d(int ext_nid, int crit, void *ext_struc);
  414. This function sets up an extension from its internal structure. The ext_nid
  415. parameter is the NID of the extension and 'crit' is the critical flag.
  416. 4. Context functions.
  417. The following functions set and manipulate an extension context structure.
  418. The purpose of the extension context is to allow the extension code to
  419. access various structures relating to the "environment" of the certificate:
  420. for example the issuers certificate or the certificate request.
  421. void X509V3_set_ctx(X509V3_CTX *ctx, X509 *issuer, X509 *subject,
  422. X509_REQ *req, X509_CRL *crl, int flags);
  423. This function sets up an X509V3_CTX structure with details of the certificate
  424. environment: specifically the issuers certificate, the subject certificate,
  425. the certificate request and the CRL: if these are not relevant or not
  426. available then they can be set to NULL. The 'flags' parameter should be set
  427. to zero.
  428. X509V3_set_ctx_test(ctx)
  429. This macro is used to set the 'ctx' structure to a 'test' value: this is to
  430. allow the syntax of an extension (or configuration file) to be tested.
  431. X509V3_set_ctx_nodb(ctx)
  432. This macro is used when no configuration database is present.
  433. void X509V3_set_conf_lhash(X509V3_CTX *ctx, LHASH *lhash);
  434. This function is used to set the configuration database when it is an LHASH
  435. structure: typically a configuration file.
  436. The following functions are used to access a configuration database: they
  437. should only be used in RAW extensions.
  438. char * X509V3_get_string(X509V3_CTX *ctx, char *name, char *section);
  439. This function returns the value of the parameter "name" in "section", or NULL
  440. if there has been an error.
  441. void X509V3_string_free(X509V3_CTX *ctx, char *str);
  442. This function frees up the string returned by the above function.
  443. STACK_OF(CONF_VALUE) * X509V3_get_section(X509V3_CTX *ctx, char *section);
  444. This function returns a whole section as a STACK_OF(CONF_VALUE) .
  445. void X509V3_section_free( X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *section);
  446. This function frees up the STACK returned by the above function.
  447. Note: it is possible to use the extension code with a custom configuration
  448. database. To do this the "db_meth" element of the X509V3_CTX structure should
  449. be set to an X509V3_CTX_METHOD structure. This structure contains the following
  450. function pointers:
  451. char * (*get_string)(void *db, char *section, char *value);
  452. STACK_OF(CONF_VALUE) * (*get_section)(void *db, char *section);
  453. void (*free_string)(void *db, char * string);
  454. void (*free_section)(void *db, STACK_OF(CONF_VALUE) *section);
  455. these will be called and passed the 'db' element in the X509V3_CTX structure
  456. to access the database. If a given function is not implemented or not required
  457. it can be set to NULL.
  458. 5. String helper functions.
  459. There are several "i2s" and "s2i" functions that convert structures to and
  460. from ASCII strings. In all the "i2s" cases the returned string should be
  461. freed using Free() after use. Since some of these are part of other extension
  462. code they may take a 'method' parameter. Unless otherwise stated it can be
  463. safely set to NULL.
  464. char *i2s_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method, ASN1_OCTET_STRING *oct);
  465. This returns a hex string from an ASN1_OCTET_STRING.
  466. char * i2s_ASN1_INTEGER(X509V3_EXT_METHOD *meth, ASN1_INTEGER *aint);
  467. char * i2s_ASN1_ENUMERATED(X509V3_EXT_METHOD *meth, ASN1_ENUMERATED *aint);
  468. These return a string decimal representations of an ASN1_INTEGER and an
  469. ASN1_ENUMERATED type, respectively.
  470. ASN1_OCTET_STRING *s2i_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method,
  471. X509V3_CTX *ctx, char *str);
  472. This converts an ASCII hex string to an ASN1_OCTET_STRING.
  473. ASN1_INTEGER * s2i_ASN1_INTEGER(X509V3_EXT_METHOD *meth, char *value);
  474. This converts a decimal ASCII string into an ASN1_INTEGER.
  475. 6. Multi valued extension helper functions.
  476. The following functions can be used to manipulate STACKs of CONF_VALUE
  477. structures, as used by multi valued extensions.
  478. int X509V3_get_value_bool(CONF_VALUE *value, int *asn1_bool);
  479. This function expects a boolean value in 'value' and sets 'asn1_bool' to
  480. it. That is it sets it to 0 for FALSE or 0xff for TRUE. The following
  481. strings are acceptable: "TRUE", "true", "Y", "y", "YES", "yes", "FALSE"
  482. "false", "N", "n", "NO" or "no".
  483. int X509V3_get_value_int(CONF_VALUE *value, ASN1_INTEGER **aint);
  484. This accepts a decimal integer of arbitrary length and sets an ASN1_INTEGER.
  485. int X509V3_add_value(const char *name, const char *value,
  486. STACK_OF(CONF_VALUE) **extlist);
  487. This simply adds a string name and value pair.
  488. int X509V3_add_value_uchar(const char *name, const unsigned char *value,
  489. STACK_OF(CONF_VALUE) **extlist);
  490. The same as above but for an unsigned character value.
  491. int X509V3_add_value_bool(const char *name, int asn1_bool,
  492. STACK_OF(CONF_VALUE) **extlist);
  493. This adds either "TRUE" or "FALSE" depending on the value of 'asn1_bool'
  494. int X509V3_add_value_bool_nf(char *name, int asn1_bool,
  495. STACK_OF(CONF_VALUE) **extlist);
  496. This is the same as above except it adds nothing if asn1_bool is FALSE.
  497. int X509V3_add_value_int(const char *name, ASN1_INTEGER *aint,
  498. STACK_OF(CONF_VALUE) **extlist);
  499. This function adds the value of the ASN1_INTEGER in decimal form.
  500. 7. Other helper functions.
  501. <to be added>
  502. ADDING CUSTOM EXTENSIONS.
  503. Currently there are three types of supported extensions.
  504. String extensions are simple strings where the value is placed directly in the
  505. extensions, and the string returned is printed out.
  506. Multi value extensions are passed a STACK_OF(CONF_VALUE) name and value pairs
  507. or return a STACK_OF(CONF_VALUE).
  508. Raw extensions are just passed a BIO or a value and it is the extensions
  509. responsibility to handle all the necessary printing.
  510. There are two ways to add an extension. One is simply as an alias to an already
  511. existing extension. An alias is an extension that is identical in ASN1 structure
  512. to an existing extension but has a different OBJECT IDENTIFIER. This can be
  513. done by calling:
  514. int X509V3_EXT_add_alias(int nid_to, int nid_from);
  515. 'nid_to' is the new extension NID and 'nid_from' is the already existing
  516. extension NID.
  517. Alternatively an extension can be written from scratch. This involves writing
  518. the ASN1 code to encode and decode the extension and functions to print out and
  519. generate the extension from strings. The relevant functions are then placed in
  520. a X509V3_EXT_METHOD structure and int X509V3_EXT_add(X509V3_EXT_METHOD *ext);
  521. called.
  522. The X509V3_EXT_METHOD structure is described below.
  523. struct {
  524. int ext_nid;
  525. int ext_flags;
  526. X509V3_EXT_NEW ext_new;
  527. X509V3_EXT_FREE ext_free;
  528. X509V3_EXT_D2I d2i;
  529. X509V3_EXT_I2D i2d;
  530. X509V3_EXT_I2S i2s;
  531. X509V3_EXT_S2I s2i;
  532. X509V3_EXT_I2V i2v;
  533. X509V3_EXT_V2I v2i;
  534. X509V3_EXT_R2I r2i;
  535. X509V3_EXT_I2R i2r;
  536. void *usr_data;
  537. };
  538. The elements have the following meanings.
  539. ext_nid is the NID of the object identifier of the extension.
  540. ext_flags is set of flags. Currently the only external flag is
  541. X509V3_EXT_MULTILINE which means a multi valued extensions
  542. should be printed on separate lines.
  543. usr_data is an extension specific pointer to any relevant data. This
  544. allows extensions to share identical code but have different
  545. uses. An example of this is the bit string extension which uses
  546. usr_data to contain a list of the bit names.
  547. All the remaining elements are function pointers.
  548. ext_new is a pointer to a function that allocates memory for the
  549. extension ASN1 structure: for example ASN1_OBJECT_new().
  550. ext_free is a pointer to a function that free up memory of the extension
  551. ASN1 structure: for example ASN1_OBJECT_free().
  552. d2i is the standard ASN1 function that converts a DER buffer into
  553. the internal ASN1 structure: for example d2i_ASN1_IA5STRING().
  554. i2d is the standard ASN1 function that converts the internal
  555. structure into the DER representation: for example
  556. i2d_ASN1_IA5STRING().
  557. The remaining functions are depend on the type of extension. One i2X and
  558. one X2i should be set and the rest set to NULL. The types set do not need
  559. to match up, for example the extension could be set using the multi valued
  560. v2i function and printed out using the raw i2r.
  561. All functions have the X509V3_EXT_METHOD passed to them in the 'method'
  562. parameter and an X509V3_CTX structure. Extension code can then access the
  563. parent structure via the 'method' parameter to for example make use of the value
  564. of usr_data. If the code needs to use detail relating to the request it can
  565. use the 'ctx' parameter.
  566. A note should be given here about the 'flags' member of the 'ctx' parameter.
  567. If it has the value CTX_TEST then the configuration syntax is being checked
  568. and no actual certificate or CRL exists. Therefore any attempt in the config
  569. file to access such information should silently succeed. If the syntax is OK
  570. then it should simply return a (possibly bogus) extension, otherwise it
  571. should return NULL.
  572. char *i2s(struct v3_ext_method *method, void *ext);
  573. This function takes the internal structure in the ext parameter and returns
  574. a Malloc'ed string representing its value.
  575. void * s2i(struct v3_ext_method *method, struct v3_ext_ctx *ctx, char *str);
  576. This function takes the string representation in the ext parameter and returns
  577. an allocated internal structure: ext_free() will be used on this internal
  578. structure after use.
  579. i2v and v2i handle a STACK_OF(CONF_VALUE):
  580. typedef struct
  581. {
  582. char *section;
  583. char *name;
  584. char *value;
  585. } CONF_VALUE;
  586. Only the name and value members are currently used.
  587. STACK_OF(CONF_VALUE) * i2v(struct v3_ext_method *method, void *ext);
  588. This function is passed the internal structure in the ext parameter and
  589. returns a STACK of CONF_VALUE structures. The values of name, value,
  590. section and the structure itself will be freed up with Free after use.
  591. Several helper functions are available to add values to this STACK.
  592. void * v2i(struct v3_ext_method *method, struct v3_ext_ctx *ctx,
  593. STACK_OF(CONF_VALUE) *values);
  594. This function takes a STACK_OF(CONF_VALUE) structures and should set the
  595. values of the external structure. This typically uses the name element to
  596. determine which structure element to set and the value element to determine
  597. what to set it to. Several helper functions are available for this
  598. purpose (see above).
  599. int i2r(struct v3_ext_method *method, void *ext, BIO *out, int indent);
  600. This function is passed the internal extension structure in the ext parameter
  601. and sends out a human readable version of the extension to out. The 'indent'
  602. parameter should be noted to determine the necessary amount of indentation
  603. needed on the output.
  604. void * r2i(struct v3_ext_method *method, struct v3_ext_ctx *ctx, char *str);
  605. This is just passed the string representation of the extension. It is intended
  606. to be used for more elaborate extensions where the standard single and multi
  607. valued options are insufficient. They can use the 'ctx' parameter to parse the
  608. configuration database themselves. See the context functions section for details
  609. of how to do this.
  610. Note: although this type takes the same parameters as the "r2s" function there
  611. is a subtle difference. Whereas an "r2i" function can access a configuration
  612. database an "s2i" function MUST NOT. This is so the internal code can safely
  613. assume that an "s2i" function will work without a configuration database.
  614. ==============================================================================
  615. PKCS#12 Library
  616. ==============================================================================
  617. This section describes the internal PKCS#12 support. There are very few
  618. differences between the old external library and the new internal code at
  619. present. This may well change because the external library will not be updated
  620. much in future.
  621. This version now includes a couple of high level PKCS#12 functions which
  622. generally "do the right thing" and should make it much easier to handle PKCS#12
  623. structures.
  624. HIGH LEVEL FUNCTIONS.
  625. For most applications you only need concern yourself with the high level
  626. functions. They can parse and generate simple PKCS#12 files as produced by
  627. Netscape and MSIE or indeed any compliant PKCS#12 file containing a single
  628. private key and certificate pair.
  629. 1. Initialisation and cleanup.
  630. No special initialisation is needed for the internal PKCS#12 library: the
  631. standard SSLeay_add_all_algorithms() is sufficient. If you do not wish to
  632. add all algorithms (you should at least add SHA1 though) then you can manually
  633. initialise the PKCS#12 library with:
  634. PKCS12_PBE_add();
  635. The memory allocated by the PKCS#12 library is freed up when EVP_cleanup() is
  636. called or it can be directly freed with:
  637. EVP_PBE_cleanup();
  638. after this call (or EVP_cleanup() ) no more PKCS#12 library functions should
  639. be called.
  640. 2. I/O functions.
  641. i2d_PKCS12_bio(bp, p12)
  642. This writes out a PKCS12 structure to a BIO.
  643. i2d_PKCS12_fp(fp, p12)
  644. This is the same but for a FILE pointer.
  645. d2i_PKCS12_bio(bp, p12)
  646. This reads in a PKCS12 structure from a BIO.
  647. d2i_PKCS12_fp(fp, p12)
  648. This is the same but for a FILE pointer.
  649. 3. High level functions.
  650. 3.1 Parsing with PKCS12_parse().
  651. int PKCS12_parse(PKCS12 *p12, char *pass, EVP_PKEY **pkey, X509 **cert,
  652. STACK **ca);
  653. This function takes a PKCS12 structure and a password (ASCII, null terminated)
  654. and returns the private key, the corresponding certificate and any CA
  655. certificates. If any of these is not required it can be passed as a NULL.
  656. The 'ca' parameter should be either NULL, a pointer to NULL or a valid STACK
  657. structure. Typically to read in a PKCS#12 file you might do:
  658. p12 = d2i_PKCS12_fp(fp, NULL);
  659. PKCS12_parse(p12, password, &pkey, &cert, NULL); /* CAs not wanted */
  660. PKCS12_free(p12);
  661. 3.2 PKCS#12 creation with PKCS12_create().
  662. PKCS12 *PKCS12_create(char *pass, char *name, EVP_PKEY *pkey, X509 *cert,
  663. STACK *ca, int nid_key, int nid_cert, int iter,
  664. int mac_iter, int keytype);
  665. This function will create a PKCS12 structure from a given password, name,
  666. private key, certificate and optional STACK of CA certificates. The remaining
  667. 5 parameters can be set to 0 and sensible defaults will be used.
  668. The parameters nid_key and nid_cert are the key and certificate encryption
  669. algorithms, iter is the encryption iteration count, mac_iter is the MAC
  670. iteration count and keytype is the type of private key. If you really want
  671. to know what these last 5 parameters do then read the low level section.
  672. Typically to create a PKCS#12 file the following could be used:
  673. p12 = PKCS12_create(pass, "My Certificate", pkey, cert, NULL, 0,0,0,0,0);
  674. i2d_PKCS12_fp(fp, p12);
  675. PKCS12_free(p12);
  676. 3.3 Changing a PKCS#12 structure password.
  677. int PKCS12_newpass(PKCS12 *p12, char *oldpass, char *newpass);
  678. This changes the password of an already existing PKCS#12 structure. oldpass
  679. is the old password and newpass is the new one. An error occurs if the old
  680. password is incorrect.
  681. LOW LEVEL FUNCTIONS.
  682. In some cases the high level functions do not provide the necessary
  683. functionality. For example if you want to generate or parse more complex
  684. PKCS#12 files. The sample pkcs12 application uses the low level functions
  685. to display details about the internal structure of a PKCS#12 file.
  686. Introduction.
  687. This is a brief description of how a PKCS#12 file is represented internally:
  688. some knowledge of PKCS#12 is assumed.
  689. A PKCS#12 object contains several levels.
  690. At the lowest level is a PKCS12_SAFEBAG. This can contain a certificate, a
  691. CRL, a private key, encrypted or unencrypted, a set of safebags (so the
  692. structure can be nested) or other secrets (not documented at present).
  693. A safebag can optionally have attributes, currently these are: a unicode
  694. friendlyName (a Unicode string) or a localKeyID (a string of bytes).
  695. At the next level is an authSafe which is a set of safebags collected into
  696. a PKCS#7 ContentInfo. This can be just plain data, or encrypted itself.
  697. At the top level is the PKCS12 structure itself which contains a set of
  698. authSafes in an embedded PKCS#7 Contentinfo of type data. In addition it
  699. contains a MAC which is a kind of password protected digest to preserve
  700. integrity (so any unencrypted stuff below can't be tampered with).
  701. The reason for these levels is so various objects can be encrypted in various
  702. ways. For example you might want to encrypt a set of private keys with
  703. triple-DES and then include the related certificates either unencrypted or
  704. with lower encryption. Yes it's the dreaded crypto laws at work again which
  705. allow strong encryption on private keys and only weak encryption on other
  706. stuff.
  707. To build one of these things you turn all certificates and keys into safebags
  708. (with optional attributes). You collect the safebags into (one or more) STACKS
  709. and convert these into authsafes (encrypted or unencrypted). The authsafes
  710. are collected into a STACK and added to a PKCS12 structure. Finally a MAC
  711. inserted.
  712. Pulling one apart is basically the reverse process. The MAC is verified against
  713. the given password. The authsafes are extracted and each authsafe split into
  714. a set of safebags (possibly involving decryption). Finally the safebags are
  715. decomposed into the original keys and certificates and the attributes used to
  716. match up private key and certificate pairs.
  717. Anyway here are the functions that do the dirty work.
  718. 1. Construction functions.
  719. 1.1 Safebag functions.
  720. M_PKCS12_x5092certbag(x509)
  721. This macro takes an X509 structure and returns a certificate bag. The
  722. X509 structure can be freed up after calling this function.
  723. M_PKCS12_x509crl2certbag(crl)
  724. As above but for a CRL.
  725. PKCS8_PRIV_KEY_INFO *PKEY2PKCS8(EVP_PKEY *pkey)
  726. Take a private key and convert it into a PKCS#8 PrivateKeyInfo structure.
  727. Works for both RSA and DSA private keys. NB since the PKCS#8 PrivateKeyInfo
  728. structure contains a private key data in plain text form it should be free'd
  729. up as soon as it has been encrypted for security reasons (freeing up the
  730. structure zeros out the sensitive data). This can be done with
  731. PKCS8_PRIV_KEY_INFO_free().
  732. PKCS8_add_keyusage(PKCS8_PRIV_KEY_INFO *p8, int usage)
  733. This sets the key type when a key is imported into MSIE or Outlook 98. Two
  734. values are currently supported: KEY_EX and KEY_SIG. KEY_EX is an exchange type
  735. key that can also be used for signing but its size is limited in the export
  736. versions of MS software to 512 bits, it is also the default. KEY_SIG is a
  737. signing only key but the keysize is unlimited (well 16K is supposed to work).
  738. If you are using the domestic version of MSIE then you can ignore this because
  739. KEY_EX is not limited and can be used for both.
  740. PKCS12_SAFEBAG *PKCS12_MAKE_KEYBAG(PKCS8_PRIV_KEY_INFO *p8)
  741. Convert a PKCS8 private key structure into a keybag. This routine embeds the
  742. p8 structure in the keybag so p8 should not be freed up or used after it is
  743. called. The p8 structure will be freed up when the safebag is freed.
  744. PKCS12_SAFEBAG *PKCS12_MAKE_SHKEYBAG(int pbe_nid, unsigned char *pass, int passlen, unsigned char *salt, int saltlen, int iter, PKCS8_PRIV_KEY_INFO *p8)
  745. Convert a PKCS#8 structure into a shrouded key bag (encrypted). p8 is not
  746. embedded and can be freed up after use.
  747. int PKCS12_add_localkeyid(PKCS12_SAFEBAG *bag, unsigned char *name, int namelen)
  748. int PKCS12_add_friendlyname(PKCS12_SAFEBAG *bag, unsigned char *name, int namelen)
  749. Add a local key id or a friendlyname to a safebag.
  750. 1.2 Authsafe functions.
  751. PKCS7 *PKCS12_pack_p7data(STACK *sk)
  752. Take a stack of safebags and convert them into an unencrypted authsafe. The
  753. stack of safebags can be freed up after calling this function.
  754. PKCS7 *PKCS12_pack_p7encdata(int pbe_nid, unsigned char *pass, int passlen, unsigned char *salt, int saltlen, int iter, STACK *bags);
  755. As above but encrypted.
  756. 1.3 PKCS12 functions.
  757. PKCS12 *PKCS12_init(int mode)
  758. Initialise a PKCS12 structure (currently mode should be NID_pkcs7_data).
  759. M_PKCS12_pack_authsafes(p12, safes)
  760. This macro takes a STACK of authsafes and adds them to a PKCS#12 structure.
  761. int PKCS12_set_mac(PKCS12 *p12, unsigned char *pass, int passlen, unsigned char *salt, int saltlen, int iter, EVP_MD *md_type);
  762. Add a MAC to a PKCS12 structure. If EVP_MD is NULL use SHA-1, the spec suggests
  763. that SHA-1 should be used.
  764. 2. Extraction Functions.
  765. 2.1 Safebags.
  766. M_PKCS12_bag_type(bag)
  767. Return the type of "bag". Returns one of the following
  768. NID_keyBag
  769. NID_pkcs8ShroudedKeyBag 7
  770. NID_certBag 8
  771. NID_crlBag 9
  772. NID_secretBag 10
  773. NID_safeContentsBag 11
  774. M_PKCS12_cert_bag_type(bag)
  775. Returns type of certificate bag, following are understood.
  776. NID_x509Certificate 14
  777. NID_sdsiCertificate 15
  778. M_PKCS12_crl_bag_type(bag)
  779. Returns crl bag type, currently only NID_crlBag is recognised.
  780. M_PKCS12_certbag2x509(bag)
  781. This macro extracts an X509 certificate from a certificate bag.
  782. M_PKCS12_certbag2x509crl(bag)
  783. As above but for a CRL.
  784. EVP_PKEY * PKCS82PKEY(PKCS8_PRIV_KEY_INFO *p8)
  785. Extract a private key from a PKCS8 private key info structure.
  786. M_PKCS12_decrypt_skey(bag, pass, passlen)
  787. Decrypt a shrouded key bag and return a PKCS8 private key info structure.
  788. Works with both RSA and DSA keys
  789. char *PKCS12_get_friendlyname(bag)
  790. Returns the friendlyName of a bag if present or NULL if none. The returned
  791. string is a null terminated ASCII string allocated with Malloc(). It should
  792. thus be freed up with Free() after use.
  793. 2.2 AuthSafe functions.
  794. M_PKCS12_unpack_p7data(p7)
  795. Extract a STACK of safe bags from a PKCS#7 data ContentInfo.
  796. #define M_PKCS12_unpack_p7encdata(p7, pass, passlen)
  797. As above but for an encrypted content info.
  798. 2.3 PKCS12 functions.
  799. M_PKCS12_unpack_authsafes(p12)
  800. Extract a STACK of authsafes from a PKCS12 structure.
  801. M_PKCS12_mac_present(p12)
  802. Check to see if a MAC is present.
  803. int PKCS12_verify_mac(PKCS12 *p12, unsigned char *pass, int passlen)
  804. Verify a MAC on a PKCS12 structure. Returns an error if MAC not present.
  805. Notes.
  806. 1. All the function return 0 or NULL on error.
  807. 2. Encryption based functions take a common set of parameters. These are
  808. described below.
  809. pass, passlen
  810. ASCII password and length. The password on the MAC is called the "integrity
  811. password" the encryption password is called the "privacy password" in the
  812. PKCS#12 documentation. The passwords do not have to be the same. If -1 is
  813. passed for the length it is worked out by the function itself (currently
  814. this is sometimes done whatever is passed as the length but that may change).
  815. salt, saltlen
  816. A 'salt' if salt is NULL a random salt is used. If saltlen is also zero a
  817. default length is used.
  818. iter
  819. Iteration count. This is a measure of how many times an internal function is
  820. called to encrypt the data. The larger this value is the longer it takes, it
  821. makes dictionary attacks on passwords harder. NOTE: Some implementations do
  822. not support an iteration count on the MAC. If the password for the MAC and
  823. encryption is the same then there is no point in having a high iteration
  824. count for encryption if the MAC has no count. The MAC could be attacked
  825. and the password used for the main decryption.
  826. pbe_nid
  827. This is the NID of the password based encryption method used. The following are
  828. supported.
  829. NID_pbe_WithSHA1And128BitRC4
  830. NID_pbe_WithSHA1And40BitRC4
  831. NID_pbe_WithSHA1And3_Key_TripleDES_CBC
  832. NID_pbe_WithSHA1And2_Key_TripleDES_CBC
  833. NID_pbe_WithSHA1And128BitRC2_CBC
  834. NID_pbe_WithSHA1And40BitRC2_CBC
  835. Which you use depends on the implementation you are exporting to. "Export
  836. grade" (i.e. cryptographically challenged) products cannot support all
  837. algorithms. Typically you may be able to use any encryption on shrouded key
  838. bags but they must then be placed in an unencrypted authsafe. Other authsafes
  839. may only support 40bit encryption. Of course if you are using SSLeay
  840. throughout you can strongly encrypt everything and have high iteration counts
  841. on everything.
  842. 3. For decryption routines only the password and length are needed.
  843. 4. Unlike the external version the nid's of objects are the values of the
  844. constants: that is NID_certBag is the real nid, therefore there is no
  845. PKCS12_obj_offset() function. Note the object constants are not the same as
  846. those of the external version. If you use these constants then you will need
  847. to recompile your code.
  848. 5. With the exception of PKCS12_MAKE_KEYBAG(), after calling any function or
  849. macro of the form PKCS12_MAKE_SOMETHING(other) the "other" structure can be
  850. reused or freed up safely.