]>
Commit | Line | Data |
---|---|---|
0f113f3e | 1 | /* |
da1c088f | 2 | * Copyright 1999-2023 The OpenSSL Project Authors. All Rights Reserved. |
8d8c7266 | 3 | * |
54fffdf4 | 4 | * Licensed under the Apache License 2.0 (the "License"). You may not use |
b1322259 RS |
5 | * this file except in compliance with the License. You can obtain a copy |
6 | * in the file LICENSE in the source distribution or at | |
7 | * https://www.openssl.org/source/license.html | |
8d8c7266 DSH |
8 | */ |
9 | ||
10 | #include <stdio.h> | |
b39fc560 | 11 | #include "internal/cryptlib.h" |
ec577822 | 12 | #include <openssl/pkcs12.h> |
b536880c | 13 | #include "crypto/pkcs7.h" |
706457b7 | 14 | #include "p12_local.h" |
8d8c7266 DSH |
15 | |
16 | /* Initialise a PKCS12 structure to take data */ | |
17 | ||
b536880c | 18 | PKCS12 *PKCS12_init_ex(int mode, OSSL_LIB_CTX *ctx, const char *propq) |
8d8c7266 | 19 | { |
0f113f3e | 20 | PKCS12 *pkcs12; |
75ebbd9a RS |
21 | |
22 | if ((pkcs12 = PKCS12_new()) == NULL) { | |
e077455e | 23 | ERR_raise(ERR_LIB_PKCS12, ERR_R_ASN1_LIB); |
0f113f3e MC |
24 | return NULL; |
25 | } | |
512d8117 MC |
26 | if (!ASN1_INTEGER_set(pkcs12->version, 3)) |
27 | goto err; | |
0f113f3e | 28 | pkcs12->authsafes->type = OBJ_nid2obj(mode); |
b536880c JS |
29 | |
30 | ossl_pkcs7_set0_libctx(pkcs12->authsafes, ctx); | |
31 | if (!ossl_pkcs7_set1_propq(pkcs12->authsafes, propq)) { | |
e077455e | 32 | ERR_raise(ERR_LIB_PKCS12, ERR_R_PKCS7_LIB); |
b536880c JS |
33 | goto err; |
34 | } | |
35 | ||
0f113f3e MC |
36 | switch (mode) { |
37 | case NID_pkcs7_data: | |
75ebbd9a | 38 | if ((pkcs12->authsafes->d.data = ASN1_OCTET_STRING_new()) == NULL) { |
e077455e | 39 | ERR_raise(ERR_LIB_PKCS12, ERR_R_ASN1_LIB); |
0f113f3e MC |
40 | goto err; |
41 | } | |
42 | break; | |
43 | default: | |
9311d0c4 | 44 | ERR_raise(ERR_LIB_PKCS12, PKCS12_R_UNSUPPORTED_PKCS12_MODE); |
0f113f3e MC |
45 | goto err; |
46 | } | |
0f113f3e | 47 | return pkcs12; |
e0e920b1 | 48 | |
0f113f3e | 49 | err: |
e0e920b1 | 50 | PKCS12_free(pkcs12); |
0f113f3e | 51 | return NULL; |
8d8c7266 | 52 | } |
b536880c JS |
53 | |
54 | PKCS12 *PKCS12_init(int mode) | |
55 | { | |
56 | return PKCS12_init_ex(mode, NULL, NULL); | |
57 | } | |
58 | ||
fe2a7341 | 59 | const PKCS7_CTX *ossl_pkcs12_get0_pkcs7ctx(const PKCS12 *p12) |
60 | { | |
61 | if (p12 == NULL || p12->authsafes == NULL) | |
62 | return NULL; | |
63 | return &p12->authsafes->ctx; | |
64 | } |