/src/openssl/crypto/pkcs12/p12_init.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright 1999-2023 The OpenSSL Project Authors. All Rights Reserved. |
3 | | * |
4 | | * Licensed under the Apache License 2.0 (the "License"). You may not use |
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 |
8 | | */ |
9 | | |
10 | | #include <stdio.h> |
11 | | #include "internal/cryptlib.h" |
12 | | #include <openssl/pkcs12.h> |
13 | | #include "crypto/pkcs7.h" |
14 | | #include "p12_local.h" |
15 | | |
16 | | /* Initialise a PKCS12 structure to take data */ |
17 | | |
18 | | PKCS12 *PKCS12_init_ex(int mode, OSSL_LIB_CTX *ctx, const char *propq) |
19 | 0 | { |
20 | 0 | PKCS12 *pkcs12; |
21 | |
|
22 | 0 | if ((pkcs12 = PKCS12_new()) == NULL) { |
23 | 0 | ERR_raise(ERR_LIB_PKCS12, ERR_R_ASN1_LIB); |
24 | 0 | return NULL; |
25 | 0 | } |
26 | 0 | if (!ASN1_INTEGER_set(pkcs12->version, 3)) |
27 | 0 | goto err; |
28 | 0 | pkcs12->authsafes->type = OBJ_nid2obj(mode); |
29 | |
|
30 | 0 | ossl_pkcs7_set0_libctx(pkcs12->authsafes, ctx); |
31 | 0 | if (!ossl_pkcs7_set1_propq(pkcs12->authsafes, propq)) { |
32 | 0 | ERR_raise(ERR_LIB_PKCS12, ERR_R_PKCS7_LIB); |
33 | 0 | goto err; |
34 | 0 | } |
35 | | |
36 | 0 | switch (mode) { |
37 | 0 | case NID_pkcs7_data: |
38 | 0 | if ((pkcs12->authsafes->d.data = ASN1_OCTET_STRING_new()) == NULL) { |
39 | 0 | ERR_raise(ERR_LIB_PKCS12, ERR_R_ASN1_LIB); |
40 | 0 | goto err; |
41 | 0 | } |
42 | 0 | break; |
43 | 0 | default: |
44 | 0 | ERR_raise(ERR_LIB_PKCS12, PKCS12_R_UNSUPPORTED_PKCS12_MODE); |
45 | 0 | goto err; |
46 | 0 | } |
47 | 0 | return pkcs12; |
48 | | |
49 | 0 | err: |
50 | 0 | PKCS12_free(pkcs12); |
51 | 0 | return NULL; |
52 | 0 | } |
53 | | |
54 | | PKCS12 *PKCS12_init(int mode) |
55 | 0 | { |
56 | 0 | return PKCS12_init_ex(mode, NULL, NULL); |
57 | 0 | } |
58 | | |
59 | | const PKCS7_CTX *ossl_pkcs12_get0_pkcs7ctx(const PKCS12 *p12) |
60 | 0 | { |
61 | 0 | if (p12 == NULL || p12->authsafes == NULL) |
62 | 0 | return NULL; |
63 | 0 | return &p12->authsafes->ctx; |
64 | 0 | } |