aboutsummaryrefslogtreecommitdiffstats
path: root/lib/public_key/doc/src/public_key.xml
blob: 81aedaea565e8d47259e093c2b7f330b67c28762 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
<?xml version="1.0" encoding="iso-8859-1" ?>
<!DOCTYPE erlref SYSTEM "erlref.dtd">

<erlref>
  <header>
    <copyright>
      <year>2008</year>
      <year>2011</year>
      <holder>Ericsson AB, All Rights Reserved</holder>
    </copyright>
    <legalnotice>
  The contents of this file are subject to the Erlang Public License,
  Version 1.1, (the "License"); you may not use this file except in
  compliance with the License. You should have received a copy of the
  Erlang Public License along with this software. If not, it can be
  retrieved online at http://www.erlang.org/.

  Software distributed under the License is distributed on an "AS IS"
  basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
  the License for the specific language governing rights and limitations
  under the License.

  The Initial Developer of the Original Code is Ericsson AB.
    </legalnotice>

    <title>public_key</title>
    <prepared>Ingela Anderton Andin</prepared>
    <responsible></responsible>
    <docno></docno>
    <date></date>
    <rev></rev>
  </header>
  <module>public_key</module>
  <modulesummary> API module for public key infrastructure.</modulesummary>
  <description>
    <p>This module provides functions to handle public key infrastructure
    from RFC 5280 - X.509 certificates and some parts of the PKCS-standard.
    </p>
  </description>

  <section>
    <title>COMMON DATA TYPES </title> 
    
    <note><p>All records used in this manual 
    <!--     except #policy_tree_node{}  -->
    are generated from asn1 specifications
    and are documented in the User's Guide. See <seealso 
    marker="public_key_records">Public key records</seealso> and <seealso 
    marker="cert_records">X.509 Certificate records</seealso>. 
    </p></note>
    
    <p>Use the following include directive to get access to the 
    records and constant macros described here and in the User's Guide.</p>
    
    <code> -include_lib("public_key/include/public_key.hrl"). </code>

    <p><em>Data Types </em></p> 
    
    <p><c>boolean() = true | false</c></p> 

    <p><c>string = [bytes()]</c></p>
   
    <p><c>der_encoded() = binary() </c></p>

    <p><c>decrypt_der() = binary() </c></p>
    
    <p><c>pki_asn1_type() = 'Certificate' | 'RSAPrivateKey'| 'RSAPublicKey'
    'DSAPrivateKey' | 'DSAPublicKey' | 'DHParameter' | 'SubjectPublicKeyInfo'</c></p>

     <p><c>pem_entry () = {pki_asn1_type(), der_encoded() | decrypt_der(), not_encrypted |
     {"DES-CBC" | "DES-EDE3-CBC",  crypto:rand_bytes(8)}}.</c></p>
     
    <p><c>rsa_public_key()  = #'RSAPublicKey'{}</c></p> 
    
    <p><c>rsa_private_key() = #'RSAPrivateKey'{} </c></p>

    <p><c>dsa_public_key() = {integer(),  #'Dss-Parms'{}} </c></p> 

    <p><c>rsa_private_key() = #'RSAPrivateKey'{} </c></p> 
    
    <p><c>dsa_private_key() = #'DSAPrivateKey'{}</c></p>
    
    <p><c> public_crypt_options() = [{rsa_pad, rsa_padding()}]. </c></p>

    <p><c> rsa_padding() =  'rsa_pkcs1_padding' | 'rsa_pkcs1_oaep_padding' 
    | 'rsa_no_padding'</c></p>
    
    <p><c> rsa_digest_type()  = 'md5' | 'sha' </c></p>
    
    <p><c> dss_digest_type()  = 'none' | 'sha' </c></p>
    
<!--     <p><c>policy_tree() = [Root, Children]</c></p> -->
    
<!--     <p><c>Root = #policy_tree_node{}</c></p>    -->

<!--     <p><c>Children = [] | policy_tree()</c></p> -->
	
<!--     <p> The policy_tree_node record has the following fields:</p> -->
    
<!--     <taglist> -->
      
<!--       <tag>valid_policy</tag> -->
<!--       <item> Is a single policy OID representing a -->
<!--          valid policy for the path of length x.</item> -->
      
<!--       <tag>qualifier_set</tag> -->
<!--       <item>A set of policy qualifiers associated -->
<!--          with the valid policy in certificate x.</item> -->
      
<!--       <tag>critically_indicator</tag> -->
<!--       <item>The critically_indicator indicates whether the -->
<!--          certificate policy extension in certificate x was marked as -->
<!--          critical. </item> -->
      
<!--       <tag>expected_policy_set</tag> -->
<!--       <item>The expected_policy_set contains one or more policy OIDs -->
<!--          that would satisfy this policy in the certificate x+1. </item>         -->
<!--     </taglist> -->
  </section> 

<funcs>    

  <func>
    <name>decrypt_private(CipherText, Key [, Options]) -> binary()</name>
    <fsummary>Public key decryption.</fsummary>
    <type>
      <v>CipherText = binary()</v>
      <v>Key = rsa_private_key()</v>
      <v>Options = public_crypt_options()</v>
  </type> 
  <desc> 
    <p>Public key decryption using the private key.</p> 
  </desc> 
  </func>

  <func>
    <name>decrypt_public(CipherText, Key [, Options]) - > binary()</name>
    <fsummary></fsummary>
    <type>
      <v>CipherText = binary()</v>
      <v>Key = rsa_public_key()</v>
      <v>Options = public_crypt_options()</v>
  </type> 
  <desc> 
    <p> Public key decryption using the public key.</p> 
  </desc> 
  </func> 

  <func>
    <name>der_decode(Asn1type, Der) -> term()</name>
    <fsummary> Decodes a public key asn1 der encoded entity.</fsummary>
    <type>
      <v>Asn1Type = atom() -</v>
      <d> Asn1 type present in the public_key applications
      asn1 specifications.</d>
      <v>Der = der_encoded()</v>
    </type> 
    <desc> 
      <p> Decodes a public key asn1 der encoded entity.</p> 
    </desc> 
  </func>
    
  <func>
    <name>der_encode(Asn1Type, Entity) -> der_encoded()</name>
    <fsummary> Encodes a public key entity with asn1 DER encoding.</fsummary>
    <type>
      <v>Asn1Type = atom()</v>
      <d> Asn1 type present in the public_key applications
	 asn1 specifications.</d>
      <v>Entity = term() - The erlang representation of <c> Asn1Type</c></v>
  </type> 
  <desc> 
    <p> Encodes a public key entity with asn1 DER encoding.</p> 
  </desc> 
  </func>

  <func>
    <name>pem_decode(PemBin) -> [pem_entry()]</name>
    <fsummary>Decode PEM binary data and return
    entries as asn1 der encoded entities. </fsummary>
    <type>
      <v>PemBin = binary()</v>
      <d>Example {ok, PemBin} = file:read_file("cert.pem").</d>
    </type> 
  <desc> 
    <p>Decode PEM binary data and return
    entries as asn1 der encoded entities.</p> 
  </desc> 
  </func> 
    
   <func>
    <name>pem_encode(PemEntries) -> binary()</name>
    <fsummary>Creates a PEM binary</fsummary>
    <type>
      <v> PemEntries = [pem_entry()] </v> 
  </type> 
  <desc> 
    <p>Creates a PEM binary</p> 
  </desc> 
  </func>

   <func>
    <name>pem_entry_decode(PemEntry [, Password]) -> term()</name>
    <fsummary>Decodes a pem entry.</fsummary>
    <type>
      <v> PemEntry = pem_entry() </v> 
      <v> Password = string() </v> 
  </type> 
  <desc> 
    <p>Decodes a pem entry. pem_decode/1 returns a list of pem
    entries. Note that if the pem entry is of type
    'SubjectPublickeyInfo' it will be further decoded to an
    rsa_public_key() or dsa_public_key().</p>
  </desc> 
  </func>

   <func>
    <name>pem_entry_encode(Asn1Type, Entity [,{CipherInfo, Password}]) -> pem_entry()</name>
    <fsummary> Creates a pem entry that can be fed to pem_encode/1.</fsummary>
    <type>
      <v>Asn1Type = pki_asn1_type()</v>
      <v>Entity = term() - The Erlang representation of
      <c>Asn1Type</c>.  If <c>Asn1Type</c> is 'SubjectPublicKeyInfo'
      then <c>Entity</c> must be either an rsa_public_key() or a
      dsa_public_key() and this function will create the appropriate
      'SubjectPublicKeyInfo' entry.
      </v>
      <v>CipherInfo = {"DES-CBC" | "DES-EDE3-CBC",  crypto:rand_bytes(8)}</v>
      <v>Password = string()</v> 
  </type> 
  <desc> 
    <p> Creates a pem entry that can be feed to pem_encode/1.</p> 
  </desc> 
  </func>

  <func>
    <name>encrypt_private(PlainText, Key) -> binary()</name>
    <fsummary> Public key encryption using the private key.</fsummary>
    <type>
      <v>PlainText = binary()</v>
      <v>Key = rsa_private_key()</v> 
  </type> 
  <desc> 
    <p> Public key encryption using the private key.</p> 
  </desc> 
  </func>   

  <func>
    <name>encrypt_public(PlainText, Key) -> binary()</name>
    <fsummary> Public key encryption using the public key.</fsummary>
    <type>
      <v>PlainText = binary()</v>
      <v>Key = rsa_public_key()</v> 
  </type> 
  <desc> 
    <p> Public key encryption using the public key.</p> 
  </desc> 
  </func>   
  
  <func>
    <name>pkix_decode_cert(Cert, otp|plain) ->  #'Certificate'{} | #'OTPCertificate'{}</name>
    <fsummary> Decodes an asn1 der encoded pkix x509 certificate.</fsummary>
    <type>
      <v>Cert = der_encoded()</v> 
  </type> 
  <desc> 
    <p>Decodes an asn1 der encoded pkix certificate.  The otp option
    will use the customized asn1 specification OTP-PKIX.asn1 for
    decoding and also recursively decode most of the standard
    parts.</p>
  </desc> 
  </func>

  <func>
    <name>pkix_encode(Asn1Type, Entity, otp | plain) -> der_encoded()</name>
    <fsummary>Der encodes a pkix x509 certificate or part of such a
    certificate.</fsummary>
    <type>
      <v>Asn1Type = atom()</v>
      <d>The asn1 type can be 'Certificate', 'OTPCertificate' or a subtype of either .</d>
  </type> 
  <desc> 
    <p>Der encodes a pkix x509 certificate or part of such a
    certificate. This function must be used for encoding certificates or parts of certificates
    that are decoded/created on the otp format, whereas for the plain format this
    function will directly call der_encode/2. </p> 
  </desc> 
  </func>

 <func>
    <name>pkix_is_issuer(Cert, IssuerCert) -> boolean()</name>
    <fsummary> Checks if <c>IssuerCert</c> issued <c>Cert</c> </fsummary>
    <type>
      <v>Cert = der_encode() | #'OTPCertificate'{}</v> 
      <v>IssuerCert = der_encode() | #'OTPCertificate'{}</v> 
  </type> 
  <desc> 
    <p> Checks if <c>IssuerCert</c> issued <c>Cert</c> </p> 
  </desc> 
  </func>
  
  <func>
    <name>pkix_is_fixed_dh_cert(Cert) -> boolean()</name>
    <fsummary> Checks if a Certificate is a fixed Diffie-Hellman Cert.</fsummary>
    <type>
        <v>Cert = der_encode() | #'OTPCertificate'{}</v> 
  </type> 
  <desc> 
    <p> Checks if a Certificate is a fixed Diffie-Hellman Cert.</p> 
  </desc> 
  </func>  
  
  <func>
    <name>pkix_is_self_signed(Cert) -> boolean()</name>
    <fsummary> Checks if a Certificate is self signed.</fsummary>
    <type>
       <v>Cert = der_encode() | #'OTPCertificate'{}</v> 
  </type> 
  <desc> 
    <p> Checks if a Certificate is self signed.</p> 
  </desc> 
  </func>

  <func>
    <name>pkix_issuer_id(Cert, IssuedBy) -> {ok, IssuerID} | {error, Reason}</name>
    <fsummary> Returns the issuer id.</fsummary>
    <type>
        <v>Cert = der_encode() | #'OTPCertificate'{}</v>
	<v>IssuedBy = self | other</v>
	<v>IssuerID = {integer(), {rdnSequence, [#'AttributeTypeAndValue'{}]}}</v>
	<d>The issuer id consists of the serial number and the issuers name.</d>
	<v>Reason = term()</v>
  </type> 
  <desc> 
    <p> Returns the issuer id.</p> 
  </desc> 
  </func>

  <func>
    <name>pkix_normalize_name(Issuer) -> Normalized</name>
    <fsummary>Normalizes a issuer name so that it can be easily
    compared to another issuer name. </fsummary>
    <type>
      <v>Issuer = {rdnSequence,[#'AttributeTypeAndValue'{}]}</v>
      <v>Normalized = {rdnSequence, [#'AttributeTypeAndValue'{}]}</v>
  </type> 
  <desc> 
    <p>Normalizes a issuer name so that it can be easily
    compared to another issuer name.</p> 
  </desc> 
  </func>
   
  <!-- <func> -->
  <!--   <name>pkix_path_validation()</name> -->
  <!--   <fsummary> Performs a basic path validation according to RFC 5280.</fsummary> -->
  <!--   <type> -->
  <!--     <v></v>  -->
  <!--   </type>  -->
  <!--   <desc>  -->
  <!--     <p> Performs a basic path validation according to RFC 5280.</p>  -->
  <!--   </desc>  -->
  <!-- </func> -->

  
  <func>
    <name>pkix_sign(#'OTPTBSCertificate'{}, Key) -> der_encode()</name>
    <fsummary>Signs certificate.</fsummary>
    <type>
      <v>Key = rsa_public_key() | dsa_public_key()</v> 
    </type> 
    <desc> 
      <p>Signs a 'OTPTBSCertificate'. Returns the corresponding
      der encoded certificate.</p> 
    </desc> 
  </func> 

  <func>  
    <name>pkix_verify(Cert, Key) -> boolean()</name>
    <fsummary> Verify pkix x.509 certificate signature.</fsummary>
    <type>
      <v>Cert = der_encode()</v> 
      <v>Key = rsa_public_key() | dsa_public_key()</v> 
    </type> 
  <desc> 
    <p> Verify pkix x.509 certificate signature.</p> 
  </desc> 
  </func> 

  <func>
    <name>sign(Msg, DigestType, Key) -> binary()</name>
    <fsummary> Create digital signature.</fsummary>
    <type>
       <v>Msg = binary()</v>
       <d>The msg is either the binary "plain text" data to be
       signed or in the case that digest type is <c>none</c>
       it is the hashed value of "plain text" i.e. the digest.</d>
       <v>DigestType = rsa_digest_type() | dsa_digest_type()</v>
       <v>Key = rsa_public_key() | dsa_public_key()</v> 
  </type> 
  <desc> 
    <p> Creates a digital signature.</p> 
  </desc> 
  </func>   

  <func>
    <name>verify(Msg, DigestType, Signature, Key) -> boolean()</name>
    <fsummary>Verifies a digital signature.</fsummary>
    <type>
      <v>Msg = binary()</v>
       <d>The msg is either the binary "plain text" data 
        or in the case that digest type is <c>none</c>
	it is the hashed value of "plain text" i.e. the digest.</d>
      <v>DigestType = rsa_digest_type() | dsa_digest_type()</v>
      <v>Signature = binary()</v>
      <v>Key = rsa_public_key() | dsa_public_key()</v> 
  </type> 
  <desc> 
    <p>Verifies a digital signature</p> 
  </desc> 
  </func>
  
</funcs>

</erlref>