diff options
author | tedu <> | 2014-04-18 00:10:08 +0000 |
---|---|---|
committer | tedu <> | 2014-04-18 00:10:08 +0000 |
commit | 07f5c09b19f56c323fa22ebd5efb5a4df9f5dc4d (patch) | |
tree | 6327d50d69a1982f840dc68fe928ea459e2c41e0 | |
parent | 288a9e368d9d4a72792b12a00ad69e3592d94073 (diff) | |
download | openbsd-07f5c09b19f56c323fa22ebd5efb5a4df9f5dc4d.tar.gz openbsd-07f5c09b19f56c323fa22ebd5efb5a4df9f5dc4d.tar.bz2 openbsd-07f5c09b19f56c323fa22ebd5efb5a4df9f5dc4d.zip |
putting most of the braces in the right column is the very least we can do.
108 files changed, 4068 insertions, 4060 deletions
diff --git a/src/lib/libcrypto/asn1/a_digest.c b/src/lib/libcrypto/asn1/a_digest.c index 0d463d409b..e87d4396df 100644 --- a/src/lib/libcrypto/asn1/a_digest.c +++ b/src/lib/libcrypto/asn1/a_digest.c | |||
@@ -72,7 +72,7 @@ | |||
72 | 72 | ||
73 | int ASN1_item_digest(const ASN1_ITEM *it, const EVP_MD *type, void *asn, | 73 | int ASN1_item_digest(const ASN1_ITEM *it, const EVP_MD *type, void *asn, |
74 | unsigned char *md, unsigned int *len) | 74 | unsigned char *md, unsigned int *len) |
75 | { | 75 | { |
76 | int i; | 76 | int i; |
77 | unsigned char *str = NULL; | 77 | unsigned char *str = NULL; |
78 | 78 | ||
@@ -83,4 +83,4 @@ int ASN1_item_digest(const ASN1_ITEM *it, const EVP_MD *type, void *asn, | |||
83 | return 0; | 83 | return 0; |
84 | free(str); | 84 | free(str); |
85 | return(1); | 85 | return(1); |
86 | } | 86 | } |
diff --git a/src/lib/libcrypto/asn1/a_dup.c b/src/lib/libcrypto/asn1/a_dup.c index e825b9c2d4..4482a89337 100644 --- a/src/lib/libcrypto/asn1/a_dup.c +++ b/src/lib/libcrypto/asn1/a_dup.c | |||
@@ -63,7 +63,7 @@ | |||
63 | #ifndef NO_OLD_ASN1 | 63 | #ifndef NO_OLD_ASN1 |
64 | 64 | ||
65 | void *ASN1_dup(i2d_of_void *i2d, d2i_of_void *d2i, void *x) | 65 | void *ASN1_dup(i2d_of_void *i2d, d2i_of_void *d2i, void *x) |
66 | { | 66 | { |
67 | unsigned char *b,*p; | 67 | unsigned char *b,*p; |
68 | const unsigned char *p2; | 68 | const unsigned char *p2; |
69 | int i; | 69 | int i; |
@@ -74,14 +74,16 @@ void *ASN1_dup(i2d_of_void *i2d, d2i_of_void *d2i, void *x) | |||
74 | i=i2d(x,NULL); | 74 | i=i2d(x,NULL); |
75 | b=malloc(i+10); | 75 | b=malloc(i+10); |
76 | if (b == NULL) | 76 | if (b == NULL) |
77 | { ASN1err(ASN1_F_ASN1_DUP,ERR_R_MALLOC_FAILURE); return(NULL); } | 77 | { |
78 | ASN1err(ASN1_F_ASN1_DUP,ERR_R_MALLOC_FAILURE); return(NULL); | ||
79 | } | ||
78 | p= b; | 80 | p= b; |
79 | i=i2d(x,&p); | 81 | i=i2d(x,&p); |
80 | p2= b; | 82 | p2= b; |
81 | ret=d2i(NULL,&p2,i); | 83 | ret=d2i(NULL,&p2,i); |
82 | free(b); | 84 | free(b); |
83 | return(ret); | 85 | return(ret); |
84 | } | 86 | } |
85 | 87 | ||
86 | #endif | 88 | #endif |
87 | 89 | ||
@@ -91,7 +93,7 @@ void *ASN1_dup(i2d_of_void *i2d, d2i_of_void *d2i, void *x) | |||
91 | */ | 93 | */ |
92 | 94 | ||
93 | void *ASN1_item_dup(const ASN1_ITEM *it, void *x) | 95 | void *ASN1_item_dup(const ASN1_ITEM *it, void *x) |
94 | { | 96 | { |
95 | unsigned char *b = NULL; | 97 | unsigned char *b = NULL; |
96 | const unsigned char *p; | 98 | const unsigned char *p; |
97 | long i; | 99 | long i; |
@@ -101,9 +103,11 @@ void *ASN1_item_dup(const ASN1_ITEM *it, void *x) | |||
101 | 103 | ||
102 | i=ASN1_item_i2d(x,&b,it); | 104 | i=ASN1_item_i2d(x,&b,it); |
103 | if (b == NULL) | 105 | if (b == NULL) |
104 | { ASN1err(ASN1_F_ASN1_ITEM_DUP,ERR_R_MALLOC_FAILURE); return(NULL); } | 106 | { |
107 | ASN1err(ASN1_F_ASN1_ITEM_DUP,ERR_R_MALLOC_FAILURE); return(NULL); | ||
108 | } | ||
105 | p= b; | 109 | p= b; |
106 | ret=ASN1_item_d2i(NULL,&p,i, it); | 110 | ret=ASN1_item_d2i(NULL,&p,i, it); |
107 | free(b); | 111 | free(b); |
108 | return(ret); | 112 | return(ret); |
109 | } | 113 | } |
diff --git a/src/lib/libcrypto/asn1/a_enum.c b/src/lib/libcrypto/asn1/a_enum.c index c1154dde0a..77c7c2cd88 100644 --- a/src/lib/libcrypto/asn1/a_enum.c +++ b/src/lib/libcrypto/asn1/a_enum.c | |||
@@ -67,7 +67,7 @@ | |||
67 | */ | 67 | */ |
68 | 68 | ||
69 | int ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v) | 69 | int ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v) |
70 | { | 70 | { |
71 | int j,k; | 71 | int j,k; |
72 | unsigned int i; | 72 | unsigned int i; |
73 | unsigned char buf[sizeof(long)+1]; | 73 | unsigned char buf[sizeof(long)+1]; |
@@ -75,39 +75,39 @@ int ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v) | |||
75 | 75 | ||
76 | a->type=V_ASN1_ENUMERATED; | 76 | a->type=V_ASN1_ENUMERATED; |
77 | if (a->length < (int)(sizeof(long)+1)) | 77 | if (a->length < (int)(sizeof(long)+1)) |
78 | { | 78 | { |
79 | if (a->data != NULL) | 79 | if (a->data != NULL) |
80 | free(a->data); | 80 | free(a->data); |
81 | if ((a->data=(unsigned char *)malloc(sizeof(long)+1)) != NULL) | 81 | if ((a->data=(unsigned char *)malloc(sizeof(long)+1)) != NULL) |
82 | memset((char *)a->data,0,sizeof(long)+1); | 82 | memset((char *)a->data,0,sizeof(long)+1); |
83 | } | 83 | } |
84 | if (a->data == NULL) | 84 | if (a->data == NULL) |
85 | { | 85 | { |
86 | ASN1err(ASN1_F_ASN1_ENUMERATED_SET,ERR_R_MALLOC_FAILURE); | 86 | ASN1err(ASN1_F_ASN1_ENUMERATED_SET,ERR_R_MALLOC_FAILURE); |
87 | return(0); | 87 | return(0); |
88 | } | 88 | } |
89 | d=v; | 89 | d=v; |
90 | if (d < 0) | 90 | if (d < 0) |
91 | { | 91 | { |
92 | d= -d; | 92 | d= -d; |
93 | a->type=V_ASN1_NEG_ENUMERATED; | 93 | a->type=V_ASN1_NEG_ENUMERATED; |
94 | } | 94 | } |
95 | 95 | ||
96 | for (i=0; i<sizeof(long); i++) | 96 | for (i=0; i<sizeof(long); i++) |
97 | { | 97 | { |
98 | if (d == 0) break; | 98 | if (d == 0) break; |
99 | buf[i]=(int)d&0xff; | 99 | buf[i]=(int)d&0xff; |
100 | d>>=8; | 100 | d>>=8; |
101 | } | 101 | } |
102 | j=0; | 102 | j=0; |
103 | for (k=i-1; k >=0; k--) | 103 | for (k=i-1; k >=0; k--) |
104 | a->data[j++]=buf[k]; | 104 | a->data[j++]=buf[k]; |
105 | a->length=j; | 105 | a->length=j; |
106 | return(1); | 106 | return(1); |
107 | } | 107 | } |
108 | 108 | ||
109 | long ASN1_ENUMERATED_get(ASN1_ENUMERATED *a) | 109 | long ASN1_ENUMERATED_get(ASN1_ENUMERATED *a) |
110 | { | 110 | { |
111 | int neg=0,i; | 111 | int neg=0,i; |
112 | long r=0; | 112 | long r=0; |
113 | 113 | ||
@@ -119,24 +119,24 @@ long ASN1_ENUMERATED_get(ASN1_ENUMERATED *a) | |||
119 | return -1; | 119 | return -1; |
120 | 120 | ||
121 | if (a->length > (int)sizeof(long)) | 121 | if (a->length > (int)sizeof(long)) |
122 | { | 122 | { |
123 | /* hmm... a bit ugly */ | 123 | /* hmm... a bit ugly */ |
124 | return(0xffffffffL); | 124 | return(0xffffffffL); |
125 | } | 125 | } |
126 | if (a->data == NULL) | 126 | if (a->data == NULL) |
127 | return 0; | 127 | return 0; |
128 | 128 | ||
129 | for (i=0; i<a->length; i++) | 129 | for (i=0; i<a->length; i++) |
130 | { | 130 | { |
131 | r<<=8; | 131 | r<<=8; |
132 | r|=(unsigned char)a->data[i]; | 132 | r|=(unsigned char)a->data[i]; |
133 | } | 133 | } |
134 | if (neg) r= -r; | 134 | if (neg) r= -r; |
135 | return(r); | 135 | return(r); |
136 | } | 136 | } |
137 | 137 | ||
138 | ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(BIGNUM *bn, ASN1_ENUMERATED *ai) | 138 | ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(BIGNUM *bn, ASN1_ENUMERATED *ai) |
139 | { | 139 | { |
140 | ASN1_ENUMERATED *ret; | 140 | ASN1_ENUMERATED *ret; |
141 | int len,j; | 141 | int len,j; |
142 | 142 | ||
@@ -145,38 +145,38 @@ ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(BIGNUM *bn, ASN1_ENUMERATED *ai) | |||
145 | else | 145 | else |
146 | ret=ai; | 146 | ret=ai; |
147 | if (ret == NULL) | 147 | if (ret == NULL) |
148 | { | 148 | { |
149 | ASN1err(ASN1_F_BN_TO_ASN1_ENUMERATED,ERR_R_NESTED_ASN1_ERROR); | 149 | ASN1err(ASN1_F_BN_TO_ASN1_ENUMERATED,ERR_R_NESTED_ASN1_ERROR); |
150 | goto err; | 150 | goto err; |
151 | } | 151 | } |
152 | if(BN_is_negative(bn)) ret->type = V_ASN1_NEG_ENUMERATED; | 152 | if(BN_is_negative(bn)) ret->type = V_ASN1_NEG_ENUMERATED; |
153 | else ret->type=V_ASN1_ENUMERATED; | 153 | else ret->type=V_ASN1_ENUMERATED; |
154 | j=BN_num_bits(bn); | 154 | j=BN_num_bits(bn); |
155 | len=((j == 0)?0:((j/8)+1)); | 155 | len=((j == 0)?0:((j/8)+1)); |
156 | if (ret->length < len+4) | 156 | if (ret->length < len+4) |
157 | { | 157 | { |
158 | unsigned char *new_data=realloc(ret->data, len+4); | 158 | unsigned char *new_data=realloc(ret->data, len+4); |
159 | if (!new_data) | 159 | if (!new_data) |
160 | { | 160 | { |
161 | ASN1err(ASN1_F_BN_TO_ASN1_ENUMERATED,ERR_R_MALLOC_FAILURE); | 161 | ASN1err(ASN1_F_BN_TO_ASN1_ENUMERATED,ERR_R_MALLOC_FAILURE); |
162 | goto err; | 162 | goto err; |
163 | } | ||
164 | ret->data=new_data; | ||
165 | } | 163 | } |
164 | ret->data=new_data; | ||
165 | } | ||
166 | 166 | ||
167 | ret->length=BN_bn2bin(bn,ret->data); | 167 | ret->length=BN_bn2bin(bn,ret->data); |
168 | return(ret); | 168 | return(ret); |
169 | err: | 169 | err: |
170 | if (ret != ai) M_ASN1_ENUMERATED_free(ret); | 170 | if (ret != ai) M_ASN1_ENUMERATED_free(ret); |
171 | return(NULL); | 171 | return(NULL); |
172 | } | 172 | } |
173 | 173 | ||
174 | BIGNUM *ASN1_ENUMERATED_to_BN(ASN1_ENUMERATED *ai, BIGNUM *bn) | 174 | BIGNUM *ASN1_ENUMERATED_to_BN(ASN1_ENUMERATED *ai, BIGNUM *bn) |
175 | { | 175 | { |
176 | BIGNUM *ret; | 176 | BIGNUM *ret; |
177 | 177 | ||
178 | if ((ret=BN_bin2bn(ai->data,ai->length,bn)) == NULL) | 178 | if ((ret=BN_bin2bn(ai->data,ai->length,bn)) == NULL) |
179 | ASN1err(ASN1_F_ASN1_ENUMERATED_TO_BN,ASN1_R_BN_LIB); | 179 | ASN1err(ASN1_F_ASN1_ENUMERATED_TO_BN,ASN1_R_BN_LIB); |
180 | else if(ai->type == V_ASN1_NEG_ENUMERATED) BN_set_negative(ret,1); | 180 | else if(ai->type == V_ASN1_NEG_ENUMERATED) BN_set_negative(ret,1); |
181 | return(ret); | 181 | return(ret); |
182 | } | 182 | } |
diff --git a/src/lib/libcrypto/asn1/a_gentm.c b/src/lib/libcrypto/asn1/a_gentm.c index 86666e7a20..54016dc8e7 100644 --- a/src/lib/libcrypto/asn1/a_gentm.c +++ b/src/lib/libcrypto/asn1/a_gentm.c | |||
@@ -67,41 +67,41 @@ | |||
67 | #if 0 | 67 | #if 0 |
68 | 68 | ||
69 | int i2d_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME *a, unsigned char **pp) | 69 | int i2d_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME *a, unsigned char **pp) |
70 | { | 70 | { |
71 | return(i2d_ASN1_bytes((ASN1_STRING *)a,pp, | 71 | return(i2d_ASN1_bytes((ASN1_STRING *)a,pp, |
72 | V_ASN1_GENERALIZEDTIME,V_ASN1_UNIVERSAL)); | 72 | V_ASN1_GENERALIZEDTIME,V_ASN1_UNIVERSAL)); |
73 | } | 73 | } |
74 | 74 | ||
75 | 75 | ||
76 | ASN1_GENERALIZEDTIME *d2i_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME **a, | 76 | ASN1_GENERALIZEDTIME *d2i_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME **a, |
77 | unsigned char **pp, long length) | 77 | unsigned char **pp, long length) |
78 | { | 78 | { |
79 | ASN1_GENERALIZEDTIME *ret=NULL; | 79 | ASN1_GENERALIZEDTIME *ret=NULL; |
80 | 80 | ||
81 | ret=(ASN1_GENERALIZEDTIME *)d2i_ASN1_bytes((ASN1_STRING **)a,pp,length, | 81 | ret=(ASN1_GENERALIZEDTIME *)d2i_ASN1_bytes((ASN1_STRING **)a,pp,length, |
82 | V_ASN1_GENERALIZEDTIME,V_ASN1_UNIVERSAL); | 82 | V_ASN1_GENERALIZEDTIME,V_ASN1_UNIVERSAL); |
83 | if (ret == NULL) | 83 | if (ret == NULL) |
84 | { | 84 | { |
85 | ASN1err(ASN1_F_D2I_ASN1_GENERALIZEDTIME,ERR_R_NESTED_ASN1_ERROR); | 85 | ASN1err(ASN1_F_D2I_ASN1_GENERALIZEDTIME,ERR_R_NESTED_ASN1_ERROR); |
86 | return(NULL); | 86 | return(NULL); |
87 | } | 87 | } |
88 | if (!ASN1_GENERALIZEDTIME_check(ret)) | 88 | if (!ASN1_GENERALIZEDTIME_check(ret)) |
89 | { | 89 | { |
90 | ASN1err(ASN1_F_D2I_ASN1_GENERALIZEDTIME,ASN1_R_INVALID_TIME_FORMAT); | 90 | ASN1err(ASN1_F_D2I_ASN1_GENERALIZEDTIME,ASN1_R_INVALID_TIME_FORMAT); |
91 | goto err; | 91 | goto err; |
92 | } | 92 | } |
93 | 93 | ||
94 | return(ret); | 94 | return(ret); |
95 | err: | 95 | err: |
96 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) | 96 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) |
97 | M_ASN1_GENERALIZEDTIME_free(ret); | 97 | M_ASN1_GENERALIZEDTIME_free(ret); |
98 | return(NULL); | 98 | return(NULL); |
99 | } | 99 | } |
100 | 100 | ||
101 | #endif | 101 | #endif |
102 | 102 | ||
103 | int ASN1_GENERALIZEDTIME_check(ASN1_GENERALIZEDTIME *d) | 103 | int ASN1_GENERALIZEDTIME_check(ASN1_GENERALIZEDTIME *d) |
104 | { | 104 | { |
105 | static const int min[9]={ 0, 0, 1, 1, 0, 0, 0, 0, 0}; | 105 | static const int min[9]={ 0, 0, 1, 1, 0, 0, 0, 0, 0}; |
106 | static const int max[9]={99, 99,12,31,23,59,59,12,59}; | 106 | static const int max[9]={99, 99,12,31,23,59,59,12,59}; |
107 | char *a; | 107 | char *a; |
@@ -117,10 +117,10 @@ int ASN1_GENERALIZEDTIME_check(ASN1_GENERALIZEDTIME *d) | |||
117 | */ | 117 | */ |
118 | if (l < 13) goto err; | 118 | if (l < 13) goto err; |
119 | for (i=0; i<7; i++) | 119 | for (i=0; i<7; i++) |
120 | { | 120 | { |
121 | if ((i == 6) && ((a[o] == 'Z') || | 121 | if ((i == 6) && ((a[o] == 'Z') || |
122 | (a[o] == '+') || (a[o] == '-'))) | 122 | (a[o] == '+') || (a[o] == '-'))) |
123 | { i++; break; } | 123 | { i++; break; } |
124 | if ((a[o] < '0') || (a[o] > '9')) goto err; | 124 | if ((a[o] < '0') || (a[o] > '9')) goto err; |
125 | n= a[o]-'0'; | 125 | n= a[o]-'0'; |
126 | if (++o > l) goto err; | 126 | if (++o > l) goto err; |
@@ -130,28 +130,28 @@ int ASN1_GENERALIZEDTIME_check(ASN1_GENERALIZEDTIME *d) | |||
130 | if (++o > l) goto err; | 130 | if (++o > l) goto err; |
131 | 131 | ||
132 | if ((n < min[i]) || (n > max[i])) goto err; | 132 | if ((n < min[i]) || (n > max[i])) goto err; |
133 | } | 133 | } |
134 | /* Optional fractional seconds: decimal point followed by one | 134 | /* Optional fractional seconds: decimal point followed by one |
135 | * or more digits. | 135 | * or more digits. |
136 | */ | 136 | */ |
137 | if (a[o] == '.') | 137 | if (a[o] == '.') |
138 | { | 138 | { |
139 | if (++o > l) goto err; | 139 | if (++o > l) goto err; |
140 | i = o; | 140 | i = o; |
141 | while ((a[o] >= '0') && (a[o] <= '9') && (o <= l)) | 141 | while ((a[o] >= '0') && (a[o] <= '9') && (o <= l)) |
142 | o++; | 142 | o++; |
143 | /* Must have at least one digit after decimal point */ | 143 | /* Must have at least one digit after decimal point */ |
144 | if (i == o) goto err; | 144 | if (i == o) goto err; |
145 | } | 145 | } |
146 | 146 | ||
147 | if (a[o] == 'Z') | 147 | if (a[o] == 'Z') |
148 | o++; | 148 | o++; |
149 | else if ((a[o] == '+') || (a[o] == '-')) | 149 | else if ((a[o] == '+') || (a[o] == '-')) |
150 | { | 150 | { |
151 | o++; | 151 | o++; |
152 | if (o+4 > l) goto err; | 152 | if (o+4 > l) goto err; |
153 | for (i=7; i<9; i++) | 153 | for (i=7; i<9; i++) |
154 | { | 154 | { |
155 | if ((a[o] < '0') || (a[o] > '9')) goto err; | 155 | if ((a[o] < '0') || (a[o] > '9')) goto err; |
156 | n= a[o]-'0'; | 156 | n= a[o]-'0'; |
157 | o++; | 157 | o++; |
@@ -159,49 +159,49 @@ int ASN1_GENERALIZEDTIME_check(ASN1_GENERALIZEDTIME *d) | |||
159 | n=(n*10)+ a[o]-'0'; | 159 | n=(n*10)+ a[o]-'0'; |
160 | if ((n < min[i]) || (n > max[i])) goto err; | 160 | if ((n < min[i]) || (n > max[i])) goto err; |
161 | o++; | 161 | o++; |
162 | } | ||
163 | } | 162 | } |
163 | } | ||
164 | else | 164 | else |
165 | { | 165 | { |
166 | /* Missing time zone information. */ | 166 | /* Missing time zone information. */ |
167 | goto err; | 167 | goto err; |
168 | } | 168 | } |
169 | return(o == l); | 169 | return(o == l); |
170 | err: | 170 | err: |
171 | return(0); | 171 | return(0); |
172 | } | 172 | } |
173 | 173 | ||
174 | int ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s, const char *str) | 174 | int ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s, const char *str) |
175 | { | 175 | { |
176 | ASN1_GENERALIZEDTIME t; | 176 | ASN1_GENERALIZEDTIME t; |
177 | 177 | ||
178 | t.type=V_ASN1_GENERALIZEDTIME; | 178 | t.type=V_ASN1_GENERALIZEDTIME; |
179 | t.length=strlen(str); | 179 | t.length=strlen(str); |
180 | t.data=(unsigned char *)str; | 180 | t.data=(unsigned char *)str; |
181 | if (ASN1_GENERALIZEDTIME_check(&t)) | 181 | if (ASN1_GENERALIZEDTIME_check(&t)) |
182 | { | 182 | { |
183 | if (s != NULL) | 183 | if (s != NULL) |
184 | { | 184 | { |
185 | if (!ASN1_STRING_set((ASN1_STRING *)s, | 185 | if (!ASN1_STRING_set((ASN1_STRING *)s, |
186 | (unsigned char *)str,t.length)) | 186 | (unsigned char *)str,t.length)) |
187 | return 0; | 187 | return 0; |
188 | s->type=V_ASN1_GENERALIZEDTIME; | 188 | s->type=V_ASN1_GENERALIZEDTIME; |
189 | } | ||
190 | return(1); | ||
191 | } | 189 | } |
190 | return(1); | ||
191 | } | ||
192 | else | 192 | else |
193 | return(0); | 193 | return(0); |
194 | } | 194 | } |
195 | 195 | ||
196 | ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s, | 196 | ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s, |
197 | time_t t) | 197 | time_t t) |
198 | { | 198 | { |
199 | return ASN1_GENERALIZEDTIME_adj(s, t, 0, 0); | 199 | return ASN1_GENERALIZEDTIME_adj(s, t, 0, 0); |
200 | } | 200 | } |
201 | 201 | ||
202 | ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_adj(ASN1_GENERALIZEDTIME *s, | 202 | ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_adj(ASN1_GENERALIZEDTIME *s, |
203 | time_t t, int offset_day, long offset_sec) | 203 | time_t t, int offset_day, long offset_sec) |
204 | { | 204 | { |
205 | char *p; | 205 | char *p; |
206 | struct tm *ts; | 206 | struct tm *ts; |
207 | struct tm data; | 207 | struct tm data; |
@@ -217,29 +217,29 @@ ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_adj(ASN1_GENERALIZEDTIME *s, | |||
217 | return(NULL); | 217 | return(NULL); |
218 | 218 | ||
219 | if (offset_day || offset_sec) | 219 | if (offset_day || offset_sec) |
220 | { | 220 | { |
221 | if (!OPENSSL_gmtime_adj(ts, offset_day, offset_sec)) | 221 | if (!OPENSSL_gmtime_adj(ts, offset_day, offset_sec)) |
222 | return NULL; | 222 | return NULL; |
223 | } | 223 | } |
224 | 224 | ||
225 | p=(char *)s->data; | 225 | p=(char *)s->data; |
226 | if ((p == NULL) || ((size_t)s->length < len)) | 226 | if ((p == NULL) || ((size_t)s->length < len)) |
227 | { | 227 | { |
228 | p=malloc(len); | 228 | p=malloc(len); |
229 | if (p == NULL) | 229 | if (p == NULL) |
230 | { | 230 | { |
231 | ASN1err(ASN1_F_ASN1_GENERALIZEDTIME_ADJ, | 231 | ASN1err(ASN1_F_ASN1_GENERALIZEDTIME_ADJ, |
232 | ERR_R_MALLOC_FAILURE); | 232 | ERR_R_MALLOC_FAILURE); |
233 | return(NULL); | 233 | return(NULL); |
234 | } | 234 | } |
235 | if (s->data != NULL) | 235 | if (s->data != NULL) |
236 | free(s->data); | 236 | free(s->data); |
237 | s->data=(unsigned char *)p; | 237 | s->data=(unsigned char *)p; |
238 | } | 238 | } |
239 | 239 | ||
240 | (void) snprintf(p,len,"%04d%02d%02d%02d%02d%02dZ",ts->tm_year + 1900, | 240 | (void) snprintf(p,len,"%04d%02d%02d%02d%02d%02dZ",ts->tm_year + 1900, |
241 | ts->tm_mon+1,ts->tm_mday,ts->tm_hour,ts->tm_min,ts->tm_sec); | 241 | ts->tm_mon+1,ts->tm_mday,ts->tm_hour,ts->tm_min,ts->tm_sec); |
242 | s->length=strlen(p); | 242 | s->length=strlen(p); |
243 | s->type=V_ASN1_GENERALIZEDTIME; | 243 | s->type=V_ASN1_GENERALIZEDTIME; |
244 | return(s); | 244 | return(s); |
245 | } | 245 | } |
diff --git a/src/lib/libcrypto/asn1/a_i2d_fp.c b/src/lib/libcrypto/asn1/a_i2d_fp.c index 484bcd66eb..52bedb3f73 100644 --- a/src/lib/libcrypto/asn1/a_i2d_fp.c +++ b/src/lib/libcrypto/asn1/a_i2d_fp.c | |||
@@ -65,24 +65,24 @@ | |||
65 | 65 | ||
66 | #ifndef OPENSSL_NO_FP_API | 66 | #ifndef OPENSSL_NO_FP_API |
67 | int ASN1_i2d_fp(i2d_of_void *i2d, FILE *out, void *x) | 67 | int ASN1_i2d_fp(i2d_of_void *i2d, FILE *out, void *x) |
68 | { | 68 | { |
69 | BIO *b; | 69 | BIO *b; |
70 | int ret; | 70 | int ret; |
71 | 71 | ||
72 | if ((b=BIO_new(BIO_s_file())) == NULL) | 72 | if ((b=BIO_new(BIO_s_file())) == NULL) |
73 | { | 73 | { |
74 | ASN1err(ASN1_F_ASN1_I2D_FP,ERR_R_BUF_LIB); | 74 | ASN1err(ASN1_F_ASN1_I2D_FP,ERR_R_BUF_LIB); |
75 | return(0); | 75 | return(0); |
76 | } | 76 | } |
77 | BIO_set_fp(b,out,BIO_NOCLOSE); | 77 | BIO_set_fp(b,out,BIO_NOCLOSE); |
78 | ret=ASN1_i2d_bio(i2d,b,x); | 78 | ret=ASN1_i2d_bio(i2d,b,x); |
79 | BIO_free(b); | 79 | BIO_free(b); |
80 | return(ret); | 80 | return(ret); |
81 | } | 81 | } |
82 | #endif | 82 | #endif |
83 | 83 | ||
84 | int ASN1_i2d_bio(i2d_of_void *i2d, BIO *out, unsigned char *x) | 84 | int ASN1_i2d_bio(i2d_of_void *i2d, BIO *out, unsigned char *x) |
85 | { | 85 | { |
86 | char *b; | 86 | char *b; |
87 | unsigned char *p; | 87 | unsigned char *p; |
88 | int i,j=0,n,ret=1; | 88 | int i,j=0,n,ret=1; |
@@ -90,74 +90,74 @@ int ASN1_i2d_bio(i2d_of_void *i2d, BIO *out, unsigned char *x) | |||
90 | n=i2d(x,NULL); | 90 | n=i2d(x,NULL); |
91 | b=(char *)malloc(n); | 91 | b=(char *)malloc(n); |
92 | if (b == NULL) | 92 | if (b == NULL) |
93 | { | 93 | { |
94 | ASN1err(ASN1_F_ASN1_I2D_BIO,ERR_R_MALLOC_FAILURE); | 94 | ASN1err(ASN1_F_ASN1_I2D_BIO,ERR_R_MALLOC_FAILURE); |
95 | return(0); | 95 | return(0); |
96 | } | 96 | } |
97 | 97 | ||
98 | p=(unsigned char *)b; | 98 | p=(unsigned char *)b; |
99 | i2d(x,&p); | 99 | i2d(x,&p); |
100 | 100 | ||
101 | for (;;) | 101 | for (;;) |
102 | { | 102 | { |
103 | i=BIO_write(out,&(b[j]),n); | 103 | i=BIO_write(out,&(b[j]),n); |
104 | if (i == n) break; | 104 | if (i == n) break; |
105 | if (i <= 0) | 105 | if (i <= 0) |
106 | { | 106 | { |
107 | ret=0; | 107 | ret=0; |
108 | break; | 108 | break; |
109 | } | 109 | } |
110 | j+=i; | 110 | j+=i; |
111 | n-=i; | 111 | n-=i; |
112 | } | 112 | } |
113 | free(b); | 113 | free(b); |
114 | return(ret); | 114 | return(ret); |
115 | } | 115 | } |
116 | 116 | ||
117 | #endif | 117 | #endif |
118 | 118 | ||
119 | #ifndef OPENSSL_NO_FP_API | 119 | #ifndef OPENSSL_NO_FP_API |
120 | int ASN1_item_i2d_fp(const ASN1_ITEM *it, FILE *out, void *x) | 120 | int ASN1_item_i2d_fp(const ASN1_ITEM *it, FILE *out, void *x) |
121 | { | 121 | { |
122 | BIO *b; | 122 | BIO *b; |
123 | int ret; | 123 | int ret; |
124 | 124 | ||
125 | if ((b=BIO_new(BIO_s_file())) == NULL) | 125 | if ((b=BIO_new(BIO_s_file())) == NULL) |
126 | { | 126 | { |
127 | ASN1err(ASN1_F_ASN1_ITEM_I2D_FP,ERR_R_BUF_LIB); | 127 | ASN1err(ASN1_F_ASN1_ITEM_I2D_FP,ERR_R_BUF_LIB); |
128 | return(0); | 128 | return(0); |
129 | } | 129 | } |
130 | BIO_set_fp(b,out,BIO_NOCLOSE); | 130 | BIO_set_fp(b,out,BIO_NOCLOSE); |
131 | ret=ASN1_item_i2d_bio(it,b,x); | 131 | ret=ASN1_item_i2d_bio(it,b,x); |
132 | BIO_free(b); | 132 | BIO_free(b); |
133 | return(ret); | 133 | return(ret); |
134 | } | 134 | } |
135 | #endif | 135 | #endif |
136 | 136 | ||
137 | int ASN1_item_i2d_bio(const ASN1_ITEM *it, BIO *out, void *x) | 137 | int ASN1_item_i2d_bio(const ASN1_ITEM *it, BIO *out, void *x) |
138 | { | 138 | { |
139 | unsigned char *b = NULL; | 139 | unsigned char *b = NULL; |
140 | int i,j=0,n,ret=1; | 140 | int i,j=0,n,ret=1; |
141 | 141 | ||
142 | n = ASN1_item_i2d(x, &b, it); | 142 | n = ASN1_item_i2d(x, &b, it); |
143 | if (b == NULL) | 143 | if (b == NULL) |
144 | { | 144 | { |
145 | ASN1err(ASN1_F_ASN1_ITEM_I2D_BIO,ERR_R_MALLOC_FAILURE); | 145 | ASN1err(ASN1_F_ASN1_ITEM_I2D_BIO,ERR_R_MALLOC_FAILURE); |
146 | return(0); | 146 | return(0); |
147 | } | 147 | } |
148 | 148 | ||
149 | for (;;) | 149 | for (;;) |
150 | { | 150 | { |
151 | i=BIO_write(out,&(b[j]),n); | 151 | i=BIO_write(out,&(b[j]),n); |
152 | if (i == n) break; | 152 | if (i == n) break; |
153 | if (i <= 0) | 153 | if (i <= 0) |
154 | { | 154 | { |
155 | ret=0; | 155 | ret=0; |
156 | break; | 156 | break; |
157 | } | 157 | } |
158 | j+=i; | 158 | j+=i; |
159 | n-=i; | 159 | n-=i; |
160 | } | 160 | } |
161 | free(b); | 161 | free(b); |
162 | return(ret); | 162 | return(ret); |
163 | } | 163 | } |
diff --git a/src/lib/libcrypto/asn1/a_int.c b/src/lib/libcrypto/asn1/a_int.c index 6c38ace8f9..f41d462ffe 100644 --- a/src/lib/libcrypto/asn1/a_int.c +++ b/src/lib/libcrypto/asn1/a_int.c | |||
@@ -65,17 +65,17 @@ ASN1_INTEGER *ASN1_INTEGER_dup(const ASN1_INTEGER *x) | |||
65 | { return M_ASN1_INTEGER_dup(x);} | 65 | { return M_ASN1_INTEGER_dup(x);} |
66 | 66 | ||
67 | int ASN1_INTEGER_cmp(const ASN1_INTEGER *x, const ASN1_INTEGER *y) | 67 | int ASN1_INTEGER_cmp(const ASN1_INTEGER *x, const ASN1_INTEGER *y) |
68 | { | 68 | { |
69 | int neg, ret; | 69 | int neg, ret; |
70 | /* Compare signs */ | 70 | /* Compare signs */ |
71 | neg = x->type & V_ASN1_NEG; | 71 | neg = x->type & V_ASN1_NEG; |
72 | if (neg != (y->type & V_ASN1_NEG)) | 72 | if (neg != (y->type & V_ASN1_NEG)) |
73 | { | 73 | { |
74 | if (neg) | 74 | if (neg) |
75 | return -1; | 75 | return -1; |
76 | else | 76 | else |
77 | return 1; | 77 | return 1; |
78 | } | 78 | } |
79 | 79 | ||
80 | ret = ASN1_STRING_cmp(x, y); | 80 | ret = ASN1_STRING_cmp(x, y); |
81 | 81 | ||
@@ -83,7 +83,7 @@ int ASN1_INTEGER_cmp(const ASN1_INTEGER *x, const ASN1_INTEGER *y) | |||
83 | return -ret; | 83 | return -ret; |
84 | else | 84 | else |
85 | return ret; | 85 | return ret; |
86 | } | 86 | } |
87 | 87 | ||
88 | 88 | ||
89 | /* | 89 | /* |
@@ -112,7 +112,7 @@ int ASN1_INTEGER_cmp(const ASN1_INTEGER *x, const ASN1_INTEGER *y) | |||
112 | */ | 112 | */ |
113 | 113 | ||
114 | int i2c_ASN1_INTEGER(ASN1_INTEGER *a, unsigned char **pp) | 114 | int i2c_ASN1_INTEGER(ASN1_INTEGER *a, unsigned char **pp) |
115 | { | 115 | { |
116 | int pad=0,ret,i,neg; | 116 | int pad=0,ret,i,neg; |
117 | unsigned char *p,*n,pb=0; | 117 | unsigned char *p,*n,pb=0; |
118 | 118 | ||
@@ -121,17 +121,17 @@ int i2c_ASN1_INTEGER(ASN1_INTEGER *a, unsigned char **pp) | |||
121 | if (a->length == 0) | 121 | if (a->length == 0) |
122 | ret=1; | 122 | ret=1; |
123 | else | 123 | else |
124 | { | 124 | { |
125 | ret=a->length; | 125 | ret=a->length; |
126 | i=a->data[0]; | 126 | i=a->data[0]; |
127 | if (!neg && (i > 127)) { | 127 | if (!neg && (i > 127)) { |
128 | pad=1; | 128 | pad=1; |
129 | pb=0; | 129 | pb=0; |
130 | } else if(neg) { | 130 | } else if(neg) { |
131 | if(i>128) { | 131 | if(i>128) { |
132 | pad=1; | 132 | pad=1; |
133 | pb=0xFF; | 133 | pb=0xFF; |
134 | } else if(i == 128) { | 134 | } else if(i == 128) { |
135 | /* | 135 | /* |
136 | * Special case: if any other bytes non zero we pad: | 136 | * Special case: if any other bytes non zero we pad: |
137 | * otherwise we don't. | 137 | * otherwise we don't. |
@@ -140,11 +140,11 @@ int i2c_ASN1_INTEGER(ASN1_INTEGER *a, unsigned char **pp) | |||
140 | pad=1; | 140 | pad=1; |
141 | pb=0xFF; | 141 | pb=0xFF; |
142 | break; | 142 | break; |
143 | } | ||
144 | } | 143 | } |
145 | } | 144 | } |
145 | } | ||
146 | ret+=pad; | 146 | ret+=pad; |
147 | } | 147 | } |
148 | if (pp == NULL) return(ret); | 148 | if (pp == NULL) return(ret); |
149 | p= *pp; | 149 | p= *pp; |
150 | 150 | ||
@@ -161,33 +161,33 @@ int i2c_ASN1_INTEGER(ASN1_INTEGER *a, unsigned char **pp) | |||
161 | *(p--) = 0; | 161 | *(p--) = 0; |
162 | n--; | 162 | n--; |
163 | i--; | 163 | i--; |
164 | } | 164 | } |
165 | /* Complement and increment next octet */ | 165 | /* Complement and increment next octet */ |
166 | *(p--) = ((*(n--)) ^ 0xff) + 1; | 166 | *(p--) = ((*(n--)) ^ 0xff) + 1; |
167 | i--; | 167 | i--; |
168 | /* Complement any octets left */ | 168 | /* Complement any octets left */ |
169 | for(;i > 0; i--) *(p--) = *(n--) ^ 0xff; | 169 | for(;i > 0; i--) *(p--) = *(n--) ^ 0xff; |
170 | } | 170 | } |
171 | 171 | ||
172 | *pp+=ret; | 172 | *pp+=ret; |
173 | return(ret); | 173 | return(ret); |
174 | } | 174 | } |
175 | 175 | ||
176 | /* Convert just ASN1 INTEGER content octets to ASN1_INTEGER structure */ | 176 | /* Convert just ASN1 INTEGER content octets to ASN1_INTEGER structure */ |
177 | 177 | ||
178 | ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **a, const unsigned char **pp, | 178 | ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **a, const unsigned char **pp, |
179 | long len) | 179 | long len) |
180 | { | 180 | { |
181 | ASN1_INTEGER *ret=NULL; | 181 | ASN1_INTEGER *ret=NULL; |
182 | const unsigned char *p, *pend; | 182 | const unsigned char *p, *pend; |
183 | unsigned char *to,*s; | 183 | unsigned char *to,*s; |
184 | int i; | 184 | int i; |
185 | 185 | ||
186 | if ((a == NULL) || ((*a) == NULL)) | 186 | if ((a == NULL) || ((*a) == NULL)) |
187 | { | 187 | { |
188 | if ((ret=M_ASN1_INTEGER_new()) == NULL) return(NULL); | 188 | if ((ret=M_ASN1_INTEGER_new()) == NULL) return(NULL); |
189 | ret->type=V_ASN1_INTEGER; | 189 | ret->type=V_ASN1_INTEGER; |
190 | } | 190 | } |
191 | else | 191 | else |
192 | ret=(*a); | 192 | ret=(*a); |
193 | 193 | ||
@@ -198,23 +198,23 @@ ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **a, const unsigned char **pp, | |||
198 | * signifies a missing NULL parameter. */ | 198 | * signifies a missing NULL parameter. */ |
199 | s=(unsigned char *)malloc((int)len+1); | 199 | s=(unsigned char *)malloc((int)len+1); |
200 | if (s == NULL) | 200 | if (s == NULL) |
201 | { | 201 | { |
202 | i=ERR_R_MALLOC_FAILURE; | 202 | i=ERR_R_MALLOC_FAILURE; |
203 | goto err; | 203 | goto err; |
204 | } | 204 | } |
205 | to=s; | 205 | to=s; |
206 | if(!len) { | 206 | if(!len) { |
207 | /* Strictly speaking this is an illegal INTEGER but we | 207 | /* Strictly speaking this is an illegal INTEGER but we |
208 | * tolerate it. | 208 | * tolerate it. |
209 | */ | 209 | */ |
210 | ret->type=V_ASN1_INTEGER; | 210 | ret->type=V_ASN1_INTEGER; |
211 | } else if (*p & 0x80) /* a negative number */ | 211 | } else if (*p & 0x80) /* a negative number */ |
212 | { | 212 | { |
213 | ret->type=V_ASN1_NEG_INTEGER; | 213 | ret->type=V_ASN1_NEG_INTEGER; |
214 | if ((*p == 0xff) && (len != 1)) { | 214 | if ((*p == 0xff) && (len != 1)) { |
215 | p++; | 215 | p++; |
216 | len--; | 216 | len--; |
217 | } | 217 | } |
218 | i = len; | 218 | i = len; |
219 | p += i - 1; | 219 | p += i - 1; |
220 | to += i - 1; | 220 | to += i - 1; |
@@ -222,7 +222,7 @@ ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **a, const unsigned char **pp, | |||
222 | *(to--) = 0; | 222 | *(to--) = 0; |
223 | i--; | 223 | i--; |
224 | p--; | 224 | p--; |
225 | } | 225 | } |
226 | /* Special case: if all zeros then the number will be of | 226 | /* Special case: if all zeros then the number will be of |
227 | * the form FF followed by n zero bytes: this corresponds to | 227 | * the form FF followed by n zero bytes: this corresponds to |
228 | * 1 followed by n zero bytes. We've already written n zeros | 228 | * 1 followed by n zero bytes. We've already written n zeros |
@@ -234,20 +234,20 @@ ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **a, const unsigned char **pp, | |||
234 | *s = 1; | 234 | *s = 1; |
235 | s[len] = 0; | 235 | s[len] = 0; |
236 | len++; | 236 | len++; |
237 | } else { | 237 | } else { |
238 | *(to--) = (*(p--) ^ 0xff) + 1; | 238 | *(to--) = (*(p--) ^ 0xff) + 1; |
239 | i--; | 239 | i--; |
240 | for(;i > 0; i--) *(to--) = *(p--) ^ 0xff; | 240 | for(;i > 0; i--) *(to--) = *(p--) ^ 0xff; |
241 | } | 241 | } |
242 | } else { | 242 | } else { |
243 | ret->type=V_ASN1_INTEGER; | 243 | ret->type=V_ASN1_INTEGER; |
244 | if ((*p == 0) && (len != 1)) | 244 | if ((*p == 0) && (len != 1)) |
245 | { | 245 | { |
246 | p++; | 246 | p++; |
247 | len--; | 247 | len--; |
248 | } | 248 | } |
249 | memcpy(s,p,(int)len); | 249 | memcpy(s,p,(int)len); |
250 | } | 250 | } |
251 | 251 | ||
252 | if (ret->data != NULL) free(ret->data); | 252 | if (ret->data != NULL) free(ret->data); |
253 | ret->data=s; | 253 | ret->data=s; |
@@ -260,7 +260,7 @@ err: | |||
260 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) | 260 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) |
261 | M_ASN1_INTEGER_free(ret); | 261 | M_ASN1_INTEGER_free(ret); |
262 | return(NULL); | 262 | return(NULL); |
263 | } | 263 | } |
264 | 264 | ||
265 | 265 | ||
266 | /* This is a version of d2i_ASN1_INTEGER that ignores the sign bit of | 266 | /* This is a version of d2i_ASN1_INTEGER that ignores the sign bit of |
@@ -270,7 +270,7 @@ err: | |||
270 | 270 | ||
271 | ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a, const unsigned char **pp, | 271 | ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a, const unsigned char **pp, |
272 | long length) | 272 | long length) |
273 | { | 273 | { |
274 | ASN1_INTEGER *ret=NULL; | 274 | ASN1_INTEGER *ret=NULL; |
275 | const unsigned char *p; | 275 | const unsigned char *p; |
276 | unsigned char *s; | 276 | unsigned char *s; |
@@ -279,45 +279,45 @@ ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a, const unsigned char **pp, | |||
279 | int i; | 279 | int i; |
280 | 280 | ||
281 | if ((a == NULL) || ((*a) == NULL)) | 281 | if ((a == NULL) || ((*a) == NULL)) |
282 | { | 282 | { |
283 | if ((ret=M_ASN1_INTEGER_new()) == NULL) return(NULL); | 283 | if ((ret=M_ASN1_INTEGER_new()) == NULL) return(NULL); |
284 | ret->type=V_ASN1_INTEGER; | 284 | ret->type=V_ASN1_INTEGER; |
285 | } | 285 | } |
286 | else | 286 | else |
287 | ret=(*a); | 287 | ret=(*a); |
288 | 288 | ||
289 | p= *pp; | 289 | p= *pp; |
290 | inf=ASN1_get_object(&p,&len,&tag,&xclass,length); | 290 | inf=ASN1_get_object(&p,&len,&tag,&xclass,length); |
291 | if (inf & 0x80) | 291 | if (inf & 0x80) |
292 | { | 292 | { |
293 | i=ASN1_R_BAD_OBJECT_HEADER; | 293 | i=ASN1_R_BAD_OBJECT_HEADER; |
294 | goto err; | 294 | goto err; |
295 | } | 295 | } |
296 | 296 | ||
297 | if (tag != V_ASN1_INTEGER) | 297 | if (tag != V_ASN1_INTEGER) |
298 | { | 298 | { |
299 | i=ASN1_R_EXPECTING_AN_INTEGER; | 299 | i=ASN1_R_EXPECTING_AN_INTEGER; |
300 | goto err; | 300 | goto err; |
301 | } | 301 | } |
302 | 302 | ||
303 | /* We must malloc stuff, even for 0 bytes otherwise it | 303 | /* We must malloc stuff, even for 0 bytes otherwise it |
304 | * signifies a missing NULL parameter. */ | 304 | * signifies a missing NULL parameter. */ |
305 | s=(unsigned char *)malloc((int)len+1); | 305 | s=(unsigned char *)malloc((int)len+1); |
306 | if (s == NULL) | 306 | if (s == NULL) |
307 | { | 307 | { |
308 | i=ERR_R_MALLOC_FAILURE; | 308 | i=ERR_R_MALLOC_FAILURE; |
309 | goto err; | 309 | goto err; |
310 | } | 310 | } |
311 | ret->type=V_ASN1_INTEGER; | 311 | ret->type=V_ASN1_INTEGER; |
312 | if(len) { | 312 | if(len) { |
313 | if ((*p == 0) && (len != 1)) | 313 | if ((*p == 0) && (len != 1)) |
314 | { | 314 | { |
315 | p++; | 315 | p++; |
316 | len--; | 316 | len--; |
317 | } | 317 | } |
318 | memcpy(s,p,(int)len); | 318 | memcpy(s,p,(int)len); |
319 | p+=len; | 319 | p+=len; |
320 | } | 320 | } |
321 | 321 | ||
322 | if (ret->data != NULL) free(ret->data); | 322 | if (ret->data != NULL) free(ret->data); |
323 | ret->data=s; | 323 | ret->data=s; |
@@ -330,10 +330,10 @@ err: | |||
330 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) | 330 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) |
331 | M_ASN1_INTEGER_free(ret); | 331 | M_ASN1_INTEGER_free(ret); |
332 | return(NULL); | 332 | return(NULL); |
333 | } | 333 | } |
334 | 334 | ||
335 | int ASN1_INTEGER_set(ASN1_INTEGER *a, long v) | 335 | int ASN1_INTEGER_set(ASN1_INTEGER *a, long v) |
336 | { | 336 | { |
337 | int j,k; | 337 | int j,k; |
338 | unsigned int i; | 338 | unsigned int i; |
339 | unsigned char buf[sizeof(long)+1]; | 339 | unsigned char buf[sizeof(long)+1]; |
@@ -341,39 +341,39 @@ int ASN1_INTEGER_set(ASN1_INTEGER *a, long v) | |||
341 | 341 | ||
342 | a->type=V_ASN1_INTEGER; | 342 | a->type=V_ASN1_INTEGER; |
343 | if (a->length < (int)(sizeof(long)+1)) | 343 | if (a->length < (int)(sizeof(long)+1)) |
344 | { | 344 | { |
345 | if (a->data != NULL) | 345 | if (a->data != NULL) |
346 | free(a->data); | 346 | free(a->data); |
347 | if ((a->data=(unsigned char *)malloc(sizeof(long)+1)) != NULL) | 347 | if ((a->data=(unsigned char *)malloc(sizeof(long)+1)) != NULL) |
348 | memset((char *)a->data,0,sizeof(long)+1); | 348 | memset((char *)a->data,0,sizeof(long)+1); |
349 | } | 349 | } |
350 | if (a->data == NULL) | 350 | if (a->data == NULL) |
351 | { | 351 | { |
352 | ASN1err(ASN1_F_ASN1_INTEGER_SET,ERR_R_MALLOC_FAILURE); | 352 | ASN1err(ASN1_F_ASN1_INTEGER_SET,ERR_R_MALLOC_FAILURE); |
353 | return(0); | 353 | return(0); |
354 | } | 354 | } |
355 | d=v; | 355 | d=v; |
356 | if (d < 0) | 356 | if (d < 0) |
357 | { | 357 | { |
358 | d= -d; | 358 | d= -d; |
359 | a->type=V_ASN1_NEG_INTEGER; | 359 | a->type=V_ASN1_NEG_INTEGER; |
360 | } | 360 | } |
361 | 361 | ||
362 | for (i=0; i<sizeof(long); i++) | 362 | for (i=0; i<sizeof(long); i++) |
363 | { | 363 | { |
364 | if (d == 0) break; | 364 | if (d == 0) break; |
365 | buf[i]=(int)d&0xff; | 365 | buf[i]=(int)d&0xff; |
366 | d>>=8; | 366 | d>>=8; |
367 | } | 367 | } |
368 | j=0; | 368 | j=0; |
369 | for (k=i-1; k >=0; k--) | 369 | for (k=i-1; k >=0; k--) |
370 | a->data[j++]=buf[k]; | 370 | a->data[j++]=buf[k]; |
371 | a->length=j; | 371 | a->length=j; |
372 | return(1); | 372 | return(1); |
373 | } | 373 | } |
374 | 374 | ||
375 | long ASN1_INTEGER_get(const ASN1_INTEGER *a) | 375 | long ASN1_INTEGER_get(const ASN1_INTEGER *a) |
376 | { | 376 | { |
377 | int neg=0,i; | 377 | int neg=0,i; |
378 | long r=0; | 378 | long r=0; |
379 | 379 | ||
@@ -385,24 +385,24 @@ long ASN1_INTEGER_get(const ASN1_INTEGER *a) | |||
385 | return -1; | 385 | return -1; |
386 | 386 | ||
387 | if (a->length > (int)sizeof(long)) | 387 | if (a->length > (int)sizeof(long)) |
388 | { | 388 | { |
389 | /* hmm... a bit ugly, return all ones */ | 389 | /* hmm... a bit ugly, return all ones */ |
390 | return -1; | 390 | return -1; |
391 | } | 391 | } |
392 | if (a->data == NULL) | 392 | if (a->data == NULL) |
393 | return 0; | 393 | return 0; |
394 | 394 | ||
395 | for (i=0; i<a->length; i++) | 395 | for (i=0; i<a->length; i++) |
396 | { | 396 | { |
397 | r<<=8; | 397 | r<<=8; |
398 | r|=(unsigned char)a->data[i]; | 398 | r|=(unsigned char)a->data[i]; |
399 | } | 399 | } |
400 | if (neg) r= -r; | 400 | if (neg) r= -r; |
401 | return(r); | 401 | return(r); |
402 | } | 402 | } |
403 | 403 | ||
404 | ASN1_INTEGER *BN_to_ASN1_INTEGER(const BIGNUM *bn, ASN1_INTEGER *ai) | 404 | ASN1_INTEGER *BN_to_ASN1_INTEGER(const BIGNUM *bn, ASN1_INTEGER *ai) |
405 | { | 405 | { |
406 | ASN1_INTEGER *ret; | 406 | ASN1_INTEGER *ret; |
407 | int len,j; | 407 | int len,j; |
408 | 408 | ||
@@ -411,40 +411,40 @@ ASN1_INTEGER *BN_to_ASN1_INTEGER(const BIGNUM *bn, ASN1_INTEGER *ai) | |||
411 | else | 411 | else |
412 | ret=ai; | 412 | ret=ai; |
413 | if (ret == NULL) | 413 | if (ret == NULL) |
414 | { | 414 | { |
415 | ASN1err(ASN1_F_BN_TO_ASN1_INTEGER,ERR_R_NESTED_ASN1_ERROR); | 415 | ASN1err(ASN1_F_BN_TO_ASN1_INTEGER,ERR_R_NESTED_ASN1_ERROR); |
416 | goto err; | 416 | goto err; |
417 | } | 417 | } |
418 | if (BN_is_negative(bn)) | 418 | if (BN_is_negative(bn)) |
419 | ret->type = V_ASN1_NEG_INTEGER; | 419 | ret->type = V_ASN1_NEG_INTEGER; |
420 | else ret->type=V_ASN1_INTEGER; | 420 | else ret->type=V_ASN1_INTEGER; |
421 | j=BN_num_bits(bn); | 421 | j=BN_num_bits(bn); |
422 | len=((j == 0)?0:((j/8)+1)); | 422 | len=((j == 0)?0:((j/8)+1)); |
423 | if (ret->length < len+4) | 423 | if (ret->length < len+4) |
424 | { | 424 | { |
425 | unsigned char *new_data=realloc(ret->data, len+4); | 425 | unsigned char *new_data=realloc(ret->data, len+4); |
426 | if (!new_data) | 426 | if (!new_data) |
427 | { | 427 | { |
428 | ASN1err(ASN1_F_BN_TO_ASN1_INTEGER,ERR_R_MALLOC_FAILURE); | 428 | ASN1err(ASN1_F_BN_TO_ASN1_INTEGER,ERR_R_MALLOC_FAILURE); |
429 | goto err; | 429 | goto err; |
430 | } | ||
431 | ret->data=new_data; | ||
432 | } | 430 | } |
431 | ret->data=new_data; | ||
432 | } | ||
433 | ret->length=BN_bn2bin(bn,ret->data); | 433 | ret->length=BN_bn2bin(bn,ret->data); |
434 | /* Correct zero case */ | 434 | /* Correct zero case */ |
435 | if(!ret->length) | 435 | if(!ret->length) |
436 | { | 436 | { |
437 | ret->data[0] = 0; | 437 | ret->data[0] = 0; |
438 | ret->length = 1; | 438 | ret->length = 1; |
439 | } | 439 | } |
440 | return(ret); | 440 | return(ret); |
441 | err: | 441 | err: |
442 | if (ret != ai) M_ASN1_INTEGER_free(ret); | 442 | if (ret != ai) M_ASN1_INTEGER_free(ret); |
443 | return(NULL); | 443 | return(NULL); |
444 | } | 444 | } |
445 | 445 | ||
446 | BIGNUM *ASN1_INTEGER_to_BN(const ASN1_INTEGER *ai, BIGNUM *bn) | 446 | BIGNUM *ASN1_INTEGER_to_BN(const ASN1_INTEGER *ai, BIGNUM *bn) |
447 | { | 447 | { |
448 | BIGNUM *ret; | 448 | BIGNUM *ret; |
449 | 449 | ||
450 | if ((ret=BN_bin2bn(ai->data,ai->length,bn)) == NULL) | 450 | if ((ret=BN_bin2bn(ai->data,ai->length,bn)) == NULL) |
@@ -452,7 +452,7 @@ BIGNUM *ASN1_INTEGER_to_BN(const ASN1_INTEGER *ai, BIGNUM *bn) | |||
452 | else if(ai->type == V_ASN1_NEG_INTEGER) | 452 | else if(ai->type == V_ASN1_NEG_INTEGER) |
453 | BN_set_negative(ret, 1); | 453 | BN_set_negative(ret, 1); |
454 | return(ret); | 454 | return(ret); |
455 | } | 455 | } |
456 | 456 | ||
457 | IMPLEMENT_STACK_OF(ASN1_INTEGER) | 457 | IMPLEMENT_STACK_OF(ASN1_INTEGER) |
458 | IMPLEMENT_ASN1_SET_OF(ASN1_INTEGER) | 458 | IMPLEMENT_ASN1_SET_OF(ASN1_INTEGER) |
diff --git a/src/lib/libcrypto/asn1/a_object.c b/src/lib/libcrypto/asn1/a_object.c index c30f32442d..7e9eeaa2e1 100644 --- a/src/lib/libcrypto/asn1/a_object.c +++ b/src/lib/libcrypto/asn1/a_object.c | |||
@@ -65,7 +65,7 @@ | |||
65 | #include <openssl/bn.h> | 65 | #include <openssl/bn.h> |
66 | 66 | ||
67 | int i2d_ASN1_OBJECT(ASN1_OBJECT *a, unsigned char **pp) | 67 | int i2d_ASN1_OBJECT(ASN1_OBJECT *a, unsigned char **pp) |
68 | { | 68 | { |
69 | unsigned char *p; | 69 | unsigned char *p; |
70 | int objsize; | 70 | int objsize; |
71 | 71 | ||
@@ -81,10 +81,10 @@ int i2d_ASN1_OBJECT(ASN1_OBJECT *a, unsigned char **pp) | |||
81 | 81 | ||
82 | *pp=p; | 82 | *pp=p; |
83 | return(objsize); | 83 | return(objsize); |
84 | } | 84 | } |
85 | 85 | ||
86 | int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num) | 86 | int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num) |
87 | { | 87 | { |
88 | int i,first,len=0,c, use_bn; | 88 | int i,first,len=0,c, use_bn; |
89 | char ftmp[24], *tmp = ftmp; | 89 | char ftmp[24], *tmp = ftmp; |
90 | int tmpsize = sizeof ftmp; | 90 | int tmpsize = sizeof ftmp; |
@@ -101,119 +101,119 @@ int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num) | |||
101 | c= *(p++); | 101 | c= *(p++); |
102 | num--; | 102 | num--; |
103 | if ((c >= '0') && (c <= '2')) | 103 | if ((c >= '0') && (c <= '2')) |
104 | { | 104 | { |
105 | first= c-'0'; | 105 | first= c-'0'; |
106 | } | 106 | } |
107 | else | 107 | else |
108 | { | 108 | { |
109 | ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_FIRST_NUM_TOO_LARGE); | 109 | ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_FIRST_NUM_TOO_LARGE); |
110 | goto err; | 110 | goto err; |
111 | } | 111 | } |
112 | 112 | ||
113 | if (num <= 0) | 113 | if (num <= 0) |
114 | { | 114 | { |
115 | ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_MISSING_SECOND_NUMBER); | 115 | ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_MISSING_SECOND_NUMBER); |
116 | goto err; | 116 | goto err; |
117 | } | 117 | } |
118 | c= *(p++); | 118 | c= *(p++); |
119 | num--; | 119 | num--; |
120 | for (;;) | 120 | for (;;) |
121 | { | 121 | { |
122 | if (num <= 0) break; | 122 | if (num <= 0) break; |
123 | if ((c != '.') && (c != ' ')) | 123 | if ((c != '.') && (c != ' ')) |
124 | { | 124 | { |
125 | ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_INVALID_SEPARATOR); | 125 | ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_INVALID_SEPARATOR); |
126 | goto err; | 126 | goto err; |
127 | } | 127 | } |
128 | l=0; | 128 | l=0; |
129 | use_bn = 0; | 129 | use_bn = 0; |
130 | for (;;) | 130 | for (;;) |
131 | { | 131 | { |
132 | if (num <= 0) break; | 132 | if (num <= 0) break; |
133 | num--; | 133 | num--; |
134 | c= *(p++); | 134 | c= *(p++); |
135 | if ((c == ' ') || (c == '.')) | 135 | if ((c == ' ') || (c == '.')) |
136 | break; | 136 | break; |
137 | if ((c < '0') || (c > '9')) | 137 | if ((c < '0') || (c > '9')) |
138 | { | 138 | { |
139 | ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_INVALID_DIGIT); | 139 | ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_INVALID_DIGIT); |
140 | goto err; | 140 | goto err; |
141 | } | 141 | } |
142 | if (!use_bn && l >= ((ULONG_MAX - 80) / 10L)) | 142 | if (!use_bn && l >= ((ULONG_MAX - 80) / 10L)) |
143 | { | 143 | { |
144 | use_bn = 1; | 144 | use_bn = 1; |
145 | if (!bl) | 145 | if (!bl) |
146 | bl = BN_new(); | 146 | bl = BN_new(); |
147 | if (!bl || !BN_set_word(bl, l)) | 147 | if (!bl || !BN_set_word(bl, l)) |
148 | goto err; | 148 | goto err; |
149 | } | 149 | } |
150 | if (use_bn) | 150 | if (use_bn) |
151 | { | 151 | { |
152 | if (!BN_mul_word(bl, 10L) | 152 | if (!BN_mul_word(bl, 10L) |
153 | || !BN_add_word(bl, c-'0')) | 153 | || !BN_add_word(bl, c-'0')) |
154 | goto err; | 154 | goto err; |
155 | } | 155 | } |
156 | else | 156 | else |
157 | l=l*10L+(long)(c-'0'); | 157 | l=l*10L+(long)(c-'0'); |
158 | } | 158 | } |
159 | if (len == 0) | 159 | if (len == 0) |
160 | { | 160 | { |
161 | if ((first < 2) && (l >= 40)) | 161 | if ((first < 2) && (l >= 40)) |
162 | { | 162 | { |
163 | ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_SECOND_NUMBER_TOO_LARGE); | 163 | ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_SECOND_NUMBER_TOO_LARGE); |
164 | goto err; | 164 | goto err; |
165 | } | 165 | } |
166 | if (use_bn) | 166 | if (use_bn) |
167 | { | 167 | { |
168 | if (!BN_add_word(bl, first * 40)) | 168 | if (!BN_add_word(bl, first * 40)) |
169 | goto err; | 169 | goto err; |
170 | } | 170 | } |
171 | else | 171 | else |
172 | l+=(long)first*40; | 172 | l+=(long)first*40; |
173 | } | 173 | } |
174 | i=0; | 174 | i=0; |
175 | if (use_bn) | 175 | if (use_bn) |
176 | { | 176 | { |
177 | int blsize; | 177 | int blsize; |
178 | blsize = BN_num_bits(bl); | 178 | blsize = BN_num_bits(bl); |
179 | blsize = (blsize + 6)/7; | 179 | blsize = (blsize + 6)/7; |
180 | if (blsize > tmpsize) | 180 | if (blsize > tmpsize) |
181 | { | 181 | { |
182 | if (tmp != ftmp) | 182 | if (tmp != ftmp) |
183 | free(tmp); | 183 | free(tmp); |
184 | tmpsize = blsize + 32; | 184 | tmpsize = blsize + 32; |
185 | tmp = malloc(tmpsize); | 185 | tmp = malloc(tmpsize); |
186 | if (!tmp) | 186 | if (!tmp) |
187 | goto err; | 187 | goto err; |
188 | } | 188 | } |
189 | while(blsize--) | 189 | while(blsize--) |
190 | tmp[i++] = (unsigned char)BN_div_word(bl, 0x80L); | 190 | tmp[i++] = (unsigned char)BN_div_word(bl, 0x80L); |
191 | } | 191 | } |
192 | else | 192 | else |
193 | { | 193 | { |
194 | 194 | ||
195 | for (;;) | 195 | for (;;) |
196 | { | 196 | { |
197 | tmp[i++]=(unsigned char)l&0x7f; | 197 | tmp[i++]=(unsigned char)l&0x7f; |
198 | l>>=7L; | 198 | l>>=7L; |
199 | if (l == 0L) break; | 199 | if (l == 0L) break; |
200 | } | ||
201 | |||
202 | } | 200 | } |
201 | |||
202 | } | ||
203 | if (out != NULL) | 203 | if (out != NULL) |
204 | { | 204 | { |
205 | if (len+i > olen) | 205 | if (len+i > olen) |
206 | { | 206 | { |
207 | ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_BUFFER_TOO_SMALL); | 207 | ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_BUFFER_TOO_SMALL); |
208 | goto err; | 208 | goto err; |
209 | } | 209 | } |
210 | while (--i > 0) | 210 | while (--i > 0) |
211 | out[len++]=tmp[i]|0x80; | 211 | out[len++]=tmp[i]|0x80; |
212 | out[len++]=tmp[0]; | 212 | out[len++]=tmp[0]; |
213 | } | 213 | } |
214 | else | 214 | else |
215 | len+=i; | 215 | len+=i; |
216 | } | 216 | } |
217 | if (tmp != ftmp) | 217 | if (tmp != ftmp) |
218 | free(tmp); | 218 | free(tmp); |
219 | if (bl) | 219 | if (bl) |
@@ -225,7 +225,7 @@ err: | |||
225 | if (bl) | 225 | if (bl) |
226 | BN_free(bl); | 226 | BN_free(bl); |
227 | return(0); | 227 | return(0); |
228 | } | 228 | } |
229 | 229 | ||
230 | int i2t_ASN1_OBJECT(char *buf, int buf_len, ASN1_OBJECT *a) | 230 | int i2t_ASN1_OBJECT(char *buf, int buf_len, ASN1_OBJECT *a) |
231 | { | 231 | { |
@@ -233,7 +233,7 @@ int i2t_ASN1_OBJECT(char *buf, int buf_len, ASN1_OBJECT *a) | |||
233 | } | 233 | } |
234 | 234 | ||
235 | int i2a_ASN1_OBJECT(BIO *bp, ASN1_OBJECT *a) | 235 | int i2a_ASN1_OBJECT(BIO *bp, ASN1_OBJECT *a) |
236 | { | 236 | { |
237 | char buf[80], *p = buf; | 237 | char buf[80], *p = buf; |
238 | int i; | 238 | int i; |
239 | 239 | ||
@@ -241,19 +241,19 @@ int i2a_ASN1_OBJECT(BIO *bp, ASN1_OBJECT *a) | |||
241 | return(BIO_write(bp,"NULL",4)); | 241 | return(BIO_write(bp,"NULL",4)); |
242 | i=i2t_ASN1_OBJECT(buf,sizeof buf,a); | 242 | i=i2t_ASN1_OBJECT(buf,sizeof buf,a); |
243 | if (i > (int)(sizeof(buf) - 1)) | 243 | if (i > (int)(sizeof(buf) - 1)) |
244 | { | 244 | { |
245 | p = malloc(i + 1); | 245 | p = malloc(i + 1); |
246 | if (!p) | 246 | if (!p) |
247 | return -1; | 247 | return -1; |
248 | i2t_ASN1_OBJECT(p,i + 1,a); | 248 | i2t_ASN1_OBJECT(p,i + 1,a); |
249 | } | 249 | } |
250 | if (i <= 0) | 250 | if (i <= 0) |
251 | return BIO_write(bp, "<INVALID>", 9); | 251 | return BIO_write(bp, "<INVALID>", 9); |
252 | BIO_write(bp,p,i); | 252 | BIO_write(bp,p,i); |
253 | if (p != buf) | 253 | if (p != buf) |
254 | free(p); | 254 | free(p); |
255 | return(i); | 255 | return(i); |
256 | } | 256 | } |
257 | 257 | ||
258 | ASN1_OBJECT *d2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp, | 258 | ASN1_OBJECT *d2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp, |
259 | long length) | 259 | long length) |
@@ -266,16 +266,16 @@ ASN1_OBJECT *d2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp, | |||
266 | p= *pp; | 266 | p= *pp; |
267 | inf=ASN1_get_object(&p,&len,&tag,&xclass,length); | 267 | inf=ASN1_get_object(&p,&len,&tag,&xclass,length); |
268 | if (inf & 0x80) | 268 | if (inf & 0x80) |
269 | { | 269 | { |
270 | i=ASN1_R_BAD_OBJECT_HEADER; | 270 | i=ASN1_R_BAD_OBJECT_HEADER; |
271 | goto err; | 271 | goto err; |
272 | } | 272 | } |
273 | 273 | ||
274 | if (tag != V_ASN1_OBJECT) | 274 | if (tag != V_ASN1_OBJECT) |
275 | { | 275 | { |
276 | i=ASN1_R_EXPECTING_AN_OBJECT; | 276 | i=ASN1_R_EXPECTING_AN_OBJECT; |
277 | goto err; | 277 | goto err; |
278 | } | 278 | } |
279 | ret = c2i_ASN1_OBJECT(a, &p, len); | 279 | ret = c2i_ASN1_OBJECT(a, &p, len); |
280 | if(ret) *pp = p; | 280 | if(ret) *pp = p; |
281 | return ret; | 281 | return ret; |
@@ -285,7 +285,7 @@ err: | |||
285 | } | 285 | } |
286 | ASN1_OBJECT *c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp, | 286 | ASN1_OBJECT *c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp, |
287 | long len) | 287 | long len) |
288 | { | 288 | { |
289 | ASN1_OBJECT *ret=NULL; | 289 | ASN1_OBJECT *ret=NULL; |
290 | const unsigned char *p; | 290 | const unsigned char *p; |
291 | unsigned char *data; | 291 | unsigned char *data; |
@@ -294,21 +294,21 @@ ASN1_OBJECT *c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp, | |||
294 | * subidentifiers, see: X.690 8.19.2 | 294 | * subidentifiers, see: X.690 8.19.2 |
295 | */ | 295 | */ |
296 | for (i = 0, p = *pp; i < len; i++, p++) | 296 | for (i = 0, p = *pp; i < len; i++, p++) |
297 | { | 297 | { |
298 | if (*p == 0x80 && (!i || !(p[-1] & 0x80))) | 298 | if (*p == 0x80 && (!i || !(p[-1] & 0x80))) |
299 | { | 299 | { |
300 | ASN1err(ASN1_F_C2I_ASN1_OBJECT,ASN1_R_INVALID_OBJECT_ENCODING); | 300 | ASN1err(ASN1_F_C2I_ASN1_OBJECT,ASN1_R_INVALID_OBJECT_ENCODING); |
301 | return NULL; | 301 | return NULL; |
302 | } | ||
303 | } | 302 | } |
303 | } | ||
304 | 304 | ||
305 | /* only the ASN1_OBJECTs from the 'table' will have values | 305 | /* only the ASN1_OBJECTs from the 'table' will have values |
306 | * for ->sn or ->ln */ | 306 | * for ->sn or ->ln */ |
307 | if ((a == NULL) || ((*a) == NULL) || | 307 | if ((a == NULL) || ((*a) == NULL) || |
308 | !((*a)->flags & ASN1_OBJECT_FLAG_DYNAMIC)) | 308 | !((*a)->flags & ASN1_OBJECT_FLAG_DYNAMIC)) |
309 | { | 309 | { |
310 | if ((ret=ASN1_OBJECT_new()) == NULL) return(NULL); | 310 | if ((ret=ASN1_OBJECT_new()) == NULL) return(NULL); |
311 | } | 311 | } |
312 | else ret=(*a); | 312 | else ret=(*a); |
313 | 313 | ||
314 | p= *pp; | 314 | p= *pp; |
@@ -317,14 +317,14 @@ ASN1_OBJECT *c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp, | |||
317 | ret->data = NULL; | 317 | ret->data = NULL; |
318 | /* once detached we can change it */ | 318 | /* once detached we can change it */ |
319 | if ((data == NULL) || (ret->length < len)) | 319 | if ((data == NULL) || (ret->length < len)) |
320 | { | 320 | { |
321 | ret->length=0; | 321 | ret->length=0; |
322 | if (data != NULL) free(data); | 322 | if (data != NULL) free(data); |
323 | data=(unsigned char *)malloc(len ? (int)len : 1); | 323 | data=(unsigned char *)malloc(len ? (int)len : 1); |
324 | if (data == NULL) | 324 | if (data == NULL) |
325 | { i=ERR_R_MALLOC_FAILURE; goto err; } | 325 | { i=ERR_R_MALLOC_FAILURE; goto err; } |
326 | ret->flags|=ASN1_OBJECT_FLAG_DYNAMIC_DATA; | 326 | ret->flags|=ASN1_OBJECT_FLAG_DYNAMIC_DATA; |
327 | } | 327 | } |
328 | memcpy(data,p,(int)len); | 328 | memcpy(data,p,(int)len); |
329 | /* reattach data to object, after which it remains const */ | 329 | /* reattach data to object, after which it remains const */ |
330 | ret->data =data; | 330 | ret->data =data; |
@@ -342,18 +342,18 @@ err: | |||
342 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) | 342 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) |
343 | ASN1_OBJECT_free(ret); | 343 | ASN1_OBJECT_free(ret); |
344 | return(NULL); | 344 | return(NULL); |
345 | } | 345 | } |
346 | 346 | ||
347 | ASN1_OBJECT *ASN1_OBJECT_new(void) | 347 | ASN1_OBJECT *ASN1_OBJECT_new(void) |
348 | { | 348 | { |
349 | ASN1_OBJECT *ret; | 349 | ASN1_OBJECT *ret; |
350 | 350 | ||
351 | ret=(ASN1_OBJECT *)malloc(sizeof(ASN1_OBJECT)); | 351 | ret=(ASN1_OBJECT *)malloc(sizeof(ASN1_OBJECT)); |
352 | if (ret == NULL) | 352 | if (ret == NULL) |
353 | { | 353 | { |
354 | ASN1err(ASN1_F_ASN1_OBJECT_NEW,ERR_R_MALLOC_FAILURE); | 354 | ASN1err(ASN1_F_ASN1_OBJECT_NEW,ERR_R_MALLOC_FAILURE); |
355 | return(NULL); | 355 | return(NULL); |
356 | } | 356 | } |
357 | ret->length=0; | 357 | ret->length=0; |
358 | ret->data=NULL; | 358 | ret->data=NULL; |
359 | ret->nid=0; | 359 | ret->nid=0; |
@@ -361,32 +361,32 @@ ASN1_OBJECT *ASN1_OBJECT_new(void) | |||
361 | ret->ln=NULL; | 361 | ret->ln=NULL; |
362 | ret->flags=ASN1_OBJECT_FLAG_DYNAMIC; | 362 | ret->flags=ASN1_OBJECT_FLAG_DYNAMIC; |
363 | return(ret); | 363 | return(ret); |
364 | } | 364 | } |
365 | 365 | ||
366 | void ASN1_OBJECT_free(ASN1_OBJECT *a) | 366 | void ASN1_OBJECT_free(ASN1_OBJECT *a) |
367 | { | 367 | { |
368 | if (a == NULL) return; | 368 | if (a == NULL) return; |
369 | if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_STRINGS) | 369 | if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_STRINGS) |
370 | { | 370 | { |
371 | #ifndef CONST_STRICT /* disable purely for compile-time strict const checking. Doing this on a "real" compile will cause memory leaks */ | 371 | #ifndef CONST_STRICT /* disable purely for compile-time strict const checking. Doing this on a "real" compile will cause memory leaks */ |
372 | if (a->sn != NULL) free((void *)a->sn); | 372 | if (a->sn != NULL) free((void *)a->sn); |
373 | if (a->ln != NULL) free((void *)a->ln); | 373 | if (a->ln != NULL) free((void *)a->ln); |
374 | #endif | 374 | #endif |
375 | a->sn=a->ln=NULL; | 375 | a->sn=a->ln=NULL; |
376 | } | 376 | } |
377 | if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_DATA) | 377 | if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_DATA) |
378 | { | 378 | { |
379 | if (a->data != NULL) free((void *)a->data); | 379 | if (a->data != NULL) free((void *)a->data); |
380 | a->data=NULL; | 380 | a->data=NULL; |
381 | a->length=0; | 381 | a->length=0; |
382 | } | 382 | } |
383 | if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC) | 383 | if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC) |
384 | free(a); | 384 | free(a); |
385 | } | 385 | } |
386 | 386 | ||
387 | ASN1_OBJECT *ASN1_OBJECT_create(int nid, unsigned char *data, int len, | 387 | ASN1_OBJECT *ASN1_OBJECT_create(int nid, unsigned char *data, int len, |
388 | const char *sn, const char *ln) | 388 | const char *sn, const char *ln) |
389 | { | 389 | { |
390 | ASN1_OBJECT o; | 390 | ASN1_OBJECT o; |
391 | 391 | ||
392 | o.sn=sn; | 392 | o.sn=sn; |
@@ -397,7 +397,7 @@ ASN1_OBJECT *ASN1_OBJECT_create(int nid, unsigned char *data, int len, | |||
397 | o.flags=ASN1_OBJECT_FLAG_DYNAMIC|ASN1_OBJECT_FLAG_DYNAMIC_STRINGS| | 397 | o.flags=ASN1_OBJECT_FLAG_DYNAMIC|ASN1_OBJECT_FLAG_DYNAMIC_STRINGS| |
398 | ASN1_OBJECT_FLAG_DYNAMIC_DATA; | 398 | ASN1_OBJECT_FLAG_DYNAMIC_DATA; |
399 | return(OBJ_dup(&o)); | 399 | return(OBJ_dup(&o)); |
400 | } | 400 | } |
401 | 401 | ||
402 | IMPLEMENT_STACK_OF(ASN1_OBJECT) | 402 | IMPLEMENT_STACK_OF(ASN1_OBJECT) |
403 | IMPLEMENT_ASN1_SET_OF(ASN1_OBJECT) | 403 | IMPLEMENT_ASN1_SET_OF(ASN1_OBJECT) |
diff --git a/src/lib/libcrypto/asn1/a_print.c b/src/lib/libcrypto/asn1/a_print.c index 9eec5034e1..cfd0452f13 100644 --- a/src/lib/libcrypto/asn1/a_print.c +++ b/src/lib/libcrypto/asn1/a_print.c | |||
@@ -61,7 +61,7 @@ | |||
61 | #include <openssl/asn1.h> | 61 | #include <openssl/asn1.h> |
62 | 62 | ||
63 | int ASN1_PRINTABLE_type(const unsigned char *s, int len) | 63 | int ASN1_PRINTABLE_type(const unsigned char *s, int len) |
64 | { | 64 | { |
65 | int c; | 65 | int c; |
66 | int ia5=0; | 66 | int ia5=0; |
67 | int t61=0; | 67 | int t61=0; |
@@ -70,7 +70,7 @@ int ASN1_PRINTABLE_type(const unsigned char *s, int len) | |||
70 | if (s == NULL) return(V_ASN1_PRINTABLESTRING); | 70 | if (s == NULL) return(V_ASN1_PRINTABLESTRING); |
71 | 71 | ||
72 | while ((*s) && (len-- != 0)) | 72 | while ((*s) && (len-- != 0)) |
73 | { | 73 | { |
74 | c= *(s++); | 74 | c= *(s++); |
75 | if (!( ((c >= 'a') && (c <= 'z')) || | 75 | if (!( ((c >= 'a') && (c <= 'z')) || |
76 | ((c >= 'A') && (c <= 'Z')) || | 76 | ((c >= 'A') && (c <= 'Z')) || |
@@ -85,14 +85,14 @@ int ASN1_PRINTABLE_type(const unsigned char *s, int len) | |||
85 | ia5=1; | 85 | ia5=1; |
86 | if (c&0x80) | 86 | if (c&0x80) |
87 | t61=1; | 87 | t61=1; |
88 | } | 88 | } |
89 | if (t61) return(V_ASN1_T61STRING); | 89 | if (t61) return(V_ASN1_T61STRING); |
90 | if (ia5) return(V_ASN1_IA5STRING); | 90 | if (ia5) return(V_ASN1_IA5STRING); |
91 | return(V_ASN1_PRINTABLESTRING); | 91 | return(V_ASN1_PRINTABLESTRING); |
92 | } | 92 | } |
93 | 93 | ||
94 | int ASN1_UNIVERSALSTRING_to_string(ASN1_UNIVERSALSTRING *s) | 94 | int ASN1_UNIVERSALSTRING_to_string(ASN1_UNIVERSALSTRING *s) |
95 | { | 95 | { |
96 | int i; | 96 | int i; |
97 | unsigned char *p; | 97 | unsigned char *p; |
98 | 98 | ||
@@ -100,20 +100,20 @@ int ASN1_UNIVERSALSTRING_to_string(ASN1_UNIVERSALSTRING *s) | |||
100 | if ((s->length%4) != 0) return(0); | 100 | if ((s->length%4) != 0) return(0); |
101 | p=s->data; | 101 | p=s->data; |
102 | for (i=0; i<s->length; i+=4) | 102 | for (i=0; i<s->length; i+=4) |
103 | { | 103 | { |
104 | if ((p[0] != '\0') || (p[1] != '\0') || (p[2] != '\0')) | 104 | if ((p[0] != '\0') || (p[1] != '\0') || (p[2] != '\0')) |
105 | break; | 105 | break; |
106 | else | 106 | else |
107 | p+=4; | 107 | p+=4; |
108 | } | 108 | } |
109 | if (i < s->length) return(0); | 109 | if (i < s->length) return(0); |
110 | p=s->data; | 110 | p=s->data; |
111 | for (i=3; i<s->length; i+=4) | 111 | for (i=3; i<s->length; i+=4) |
112 | { | 112 | { |
113 | *(p++)=s->data[i]; | 113 | *(p++)=s->data[i]; |
114 | } | 114 | } |
115 | *(p)='\0'; | 115 | *(p)='\0'; |
116 | s->length/=4; | 116 | s->length/=4; |
117 | s->type=ASN1_PRINTABLE_type(s->data,s->length); | 117 | s->type=ASN1_PRINTABLE_type(s->data,s->length); |
118 | return(1); | 118 | return(1); |
119 | } | 119 | } |
diff --git a/src/lib/libcrypto/asn1/a_sign.c b/src/lib/libcrypto/asn1/a_sign.c index 0433b49a64..349422fe9a 100644 --- a/src/lib/libcrypto/asn1/a_sign.c +++ b/src/lib/libcrypto/asn1/a_sign.c | |||
@@ -128,22 +128,22 @@ | |||
128 | int ASN1_item_sign(const ASN1_ITEM *it, X509_ALGOR *algor1, X509_ALGOR *algor2, | 128 | int ASN1_item_sign(const ASN1_ITEM *it, X509_ALGOR *algor1, X509_ALGOR *algor2, |
129 | ASN1_BIT_STRING *signature, void *asn, EVP_PKEY *pkey, | 129 | ASN1_BIT_STRING *signature, void *asn, EVP_PKEY *pkey, |
130 | const EVP_MD *type) | 130 | const EVP_MD *type) |
131 | { | 131 | { |
132 | EVP_MD_CTX ctx; | 132 | EVP_MD_CTX ctx; |
133 | EVP_MD_CTX_init(&ctx); | 133 | EVP_MD_CTX_init(&ctx); |
134 | if (!EVP_DigestSignInit(&ctx, NULL, type, NULL, pkey)) | 134 | if (!EVP_DigestSignInit(&ctx, NULL, type, NULL, pkey)) |
135 | { | 135 | { |
136 | EVP_MD_CTX_cleanup(&ctx); | 136 | EVP_MD_CTX_cleanup(&ctx); |
137 | return 0; | 137 | return 0; |
138 | } | ||
139 | return ASN1_item_sign_ctx(it, algor1, algor2, signature, asn, &ctx); | ||
140 | } | 138 | } |
139 | return ASN1_item_sign_ctx(it, algor1, algor2, signature, asn, &ctx); | ||
140 | } | ||
141 | 141 | ||
142 | 142 | ||
143 | int ASN1_item_sign_ctx(const ASN1_ITEM *it, | 143 | int ASN1_item_sign_ctx(const ASN1_ITEM *it, |
144 | X509_ALGOR *algor1, X509_ALGOR *algor2, | 144 | X509_ALGOR *algor1, X509_ALGOR *algor2, |
145 | ASN1_BIT_STRING *signature, void *asn, EVP_MD_CTX *ctx) | 145 | ASN1_BIT_STRING *signature, void *asn, EVP_MD_CTX *ctx) |
146 | { | 146 | { |
147 | const EVP_MD *type; | 147 | const EVP_MD *type; |
148 | EVP_PKEY *pkey; | 148 | EVP_PKEY *pkey; |
149 | unsigned char *buf_in=NULL,*buf_out=NULL; | 149 | unsigned char *buf_in=NULL,*buf_out=NULL; |
@@ -155,13 +155,13 @@ int ASN1_item_sign_ctx(const ASN1_ITEM *it, | |||
155 | pkey = EVP_PKEY_CTX_get0_pkey(ctx->pctx); | 155 | pkey = EVP_PKEY_CTX_get0_pkey(ctx->pctx); |
156 | 156 | ||
157 | if (!type || !pkey) | 157 | if (!type || !pkey) |
158 | { | 158 | { |
159 | ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX, ASN1_R_CONTEXT_NOT_INITIALISED); | 159 | ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX, ASN1_R_CONTEXT_NOT_INITIALISED); |
160 | return 0; | 160 | return 0; |
161 | } | 161 | } |
162 | 162 | ||
163 | if (pkey->ameth->item_sign) | 163 | if (pkey->ameth->item_sign) |
164 | { | 164 | { |
165 | rv = pkey->ameth->item_sign(ctx, it, asn, algor1, algor2, | 165 | rv = pkey->ameth->item_sign(ctx, it, asn, algor1, algor2, |
166 | signature); | 166 | signature); |
167 | if (rv == 1) | 167 | if (rv == 1) |
@@ -176,24 +176,24 @@ int ASN1_item_sign_ctx(const ASN1_ITEM *it, | |||
176 | ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX, ERR_R_EVP_LIB); | 176 | ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX, ERR_R_EVP_LIB); |
177 | if (rv <= 1) | 177 | if (rv <= 1) |
178 | goto err; | 178 | goto err; |
179 | } | 179 | } |
180 | else | 180 | else |
181 | rv = 2; | 181 | rv = 2; |
182 | 182 | ||
183 | if (rv == 2) | 183 | if (rv == 2) |
184 | { | 184 | { |
185 | if (type->flags & EVP_MD_FLAG_PKEY_METHOD_SIGNATURE) | 185 | if (type->flags & EVP_MD_FLAG_PKEY_METHOD_SIGNATURE) |
186 | { | 186 | { |
187 | if (!pkey->ameth || | 187 | if (!pkey->ameth || |
188 | !OBJ_find_sigid_by_algs(&signid, | 188 | !OBJ_find_sigid_by_algs(&signid, |
189 | EVP_MD_nid(type), | 189 | EVP_MD_nid(type), |
190 | pkey->ameth->pkey_id)) | 190 | pkey->ameth->pkey_id)) |
191 | { | 191 | { |
192 | ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX, | 192 | ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX, |
193 | ASN1_R_DIGEST_AND_KEY_TYPE_NOT_SUPPORTED); | 193 | ASN1_R_DIGEST_AND_KEY_TYPE_NOT_SUPPORTED); |
194 | return 0; | 194 | return 0; |
195 | } | ||
196 | } | 195 | } |
196 | } | ||
197 | else | 197 | else |
198 | signid = type->pkey_type; | 198 | signid = type->pkey_type; |
199 | 199 | ||
@@ -207,25 +207,25 @@ int ASN1_item_sign_ctx(const ASN1_ITEM *it, | |||
207 | if (algor2) | 207 | if (algor2) |
208 | X509_ALGOR_set0(algor2, OBJ_nid2obj(signid), paramtype, NULL); | 208 | X509_ALGOR_set0(algor2, OBJ_nid2obj(signid), paramtype, NULL); |
209 | 209 | ||
210 | } | 210 | } |
211 | 211 | ||
212 | inl=ASN1_item_i2d(asn,&buf_in, it); | 212 | inl=ASN1_item_i2d(asn,&buf_in, it); |
213 | outll=outl=EVP_PKEY_size(pkey); | 213 | outll=outl=EVP_PKEY_size(pkey); |
214 | buf_out=malloc((unsigned int)outl); | 214 | buf_out=malloc((unsigned int)outl); |
215 | if ((buf_in == NULL) || (buf_out == NULL)) | 215 | if ((buf_in == NULL) || (buf_out == NULL)) |
216 | { | 216 | { |
217 | outl=0; | 217 | outl=0; |
218 | ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX,ERR_R_MALLOC_FAILURE); | 218 | ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX,ERR_R_MALLOC_FAILURE); |
219 | goto err; | 219 | goto err; |
220 | } | 220 | } |
221 | 221 | ||
222 | if (!EVP_DigestSignUpdate(ctx, buf_in, inl) | 222 | if (!EVP_DigestSignUpdate(ctx, buf_in, inl) |
223 | || !EVP_DigestSignFinal(ctx, buf_out, &outl)) | 223 | || !EVP_DigestSignFinal(ctx, buf_out, &outl)) |
224 | { | 224 | { |
225 | outl=0; | 225 | outl=0; |
226 | ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX,ERR_R_EVP_LIB); | 226 | ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX,ERR_R_EVP_LIB); |
227 | goto err; | 227 | goto err; |
228 | } | 228 | } |
229 | if (signature->data != NULL) free(signature->data); | 229 | if (signature->data != NULL) free(signature->data); |
230 | signature->data=buf_out; | 230 | signature->data=buf_out; |
231 | buf_out=NULL; | 231 | buf_out=NULL; |
@@ -238,8 +238,8 @@ int ASN1_item_sign_ctx(const ASN1_ITEM *it, | |||
238 | err: | 238 | err: |
239 | EVP_MD_CTX_cleanup(ctx); | 239 | EVP_MD_CTX_cleanup(ctx); |
240 | if (buf_in != NULL) | 240 | if (buf_in != NULL) |
241 | { OPENSSL_cleanse((char *)buf_in,(unsigned int)inl); free(buf_in); } | 241 | { OPENSSL_cleanse((char *)buf_in,(unsigned int)inl); free(buf_in); } |
242 | if (buf_out != NULL) | 242 | if (buf_out != NULL) |
243 | { OPENSSL_cleanse((char *)buf_out,outll); free(buf_out); } | 243 | { OPENSSL_cleanse((char *)buf_out,outll); free(buf_out); } |
244 | return(outl); | 244 | return(outl); |
245 | } | 245 | } |
diff --git a/src/lib/libcrypto/asn1/a_time.c b/src/lib/libcrypto/asn1/a_time.c index 4ade88f065..3461660b5f 100644 --- a/src/lib/libcrypto/asn1/a_time.c +++ b/src/lib/libcrypto/asn1/a_time.c | |||
@@ -73,55 +73,55 @@ IMPLEMENT_ASN1_FUNCTIONS(ASN1_TIME) | |||
73 | 73 | ||
74 | #if 0 | 74 | #if 0 |
75 | int i2d_ASN1_TIME(ASN1_TIME *a, unsigned char **pp) | 75 | int i2d_ASN1_TIME(ASN1_TIME *a, unsigned char **pp) |
76 | { | 76 | { |
77 | if(a->type == V_ASN1_UTCTIME || a->type == V_ASN1_GENERALIZEDTIME) | 77 | if(a->type == V_ASN1_UTCTIME || a->type == V_ASN1_GENERALIZEDTIME) |
78 | return(i2d_ASN1_bytes((ASN1_STRING *)a,pp, | 78 | return(i2d_ASN1_bytes((ASN1_STRING *)a,pp, |
79 | a->type ,V_ASN1_UNIVERSAL)); | 79 | a->type ,V_ASN1_UNIVERSAL)); |
80 | ASN1err(ASN1_F_I2D_ASN1_TIME,ASN1_R_EXPECTING_A_TIME); | 80 | ASN1err(ASN1_F_I2D_ASN1_TIME,ASN1_R_EXPECTING_A_TIME); |
81 | return -1; | 81 | return -1; |
82 | } | 82 | } |
83 | #endif | 83 | #endif |
84 | 84 | ||
85 | 85 | ||
86 | ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s, time_t t) | 86 | ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s, time_t t) |
87 | { | 87 | { |
88 | return ASN1_TIME_adj(s, t, 0, 0); | 88 | return ASN1_TIME_adj(s, t, 0, 0); |
89 | } | 89 | } |
90 | 90 | ||
91 | ASN1_TIME *ASN1_TIME_adj(ASN1_TIME *s, time_t t, | 91 | ASN1_TIME *ASN1_TIME_adj(ASN1_TIME *s, time_t t, |
92 | int offset_day, long offset_sec) | 92 | int offset_day, long offset_sec) |
93 | { | 93 | { |
94 | struct tm *ts; | 94 | struct tm *ts; |
95 | struct tm data; | 95 | struct tm data; |
96 | 96 | ||
97 | ts=OPENSSL_gmtime(&t,&data); | 97 | ts=OPENSSL_gmtime(&t,&data); |
98 | if (ts == NULL) | 98 | if (ts == NULL) |
99 | { | 99 | { |
100 | ASN1err(ASN1_F_ASN1_TIME_ADJ, ASN1_R_ERROR_GETTING_TIME); | 100 | ASN1err(ASN1_F_ASN1_TIME_ADJ, ASN1_R_ERROR_GETTING_TIME); |
101 | return NULL; | 101 | return NULL; |
102 | } | 102 | } |
103 | if (offset_day || offset_sec) | 103 | if (offset_day || offset_sec) |
104 | { | 104 | { |
105 | if (!OPENSSL_gmtime_adj(ts, offset_day, offset_sec)) | 105 | if (!OPENSSL_gmtime_adj(ts, offset_day, offset_sec)) |
106 | return NULL; | 106 | return NULL; |
107 | } | 107 | } |
108 | if((ts->tm_year >= 50) && (ts->tm_year < 150)) | 108 | if((ts->tm_year >= 50) && (ts->tm_year < 150)) |
109 | return ASN1_UTCTIME_adj(s, t, offset_day, offset_sec); | 109 | return ASN1_UTCTIME_adj(s, t, offset_day, offset_sec); |
110 | return ASN1_GENERALIZEDTIME_adj(s, t, offset_day, offset_sec); | 110 | return ASN1_GENERALIZEDTIME_adj(s, t, offset_day, offset_sec); |
111 | } | 111 | } |
112 | 112 | ||
113 | int ASN1_TIME_check(ASN1_TIME *t) | 113 | int ASN1_TIME_check(ASN1_TIME *t) |
114 | { | 114 | { |
115 | if (t->type == V_ASN1_GENERALIZEDTIME) | 115 | if (t->type == V_ASN1_GENERALIZEDTIME) |
116 | return ASN1_GENERALIZEDTIME_check(t); | 116 | return ASN1_GENERALIZEDTIME_check(t); |
117 | else if (t->type == V_ASN1_UTCTIME) | 117 | else if (t->type == V_ASN1_UTCTIME) |
118 | return ASN1_UTCTIME_check(t); | 118 | return ASN1_UTCTIME_check(t); |
119 | return 0; | 119 | return 0; |
120 | } | 120 | } |
121 | 121 | ||
122 | /* Convert an ASN1_TIME structure to GeneralizedTime */ | 122 | /* Convert an ASN1_TIME structure to GeneralizedTime */ |
123 | ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(ASN1_TIME *t, ASN1_GENERALIZEDTIME **out) | 123 | ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(ASN1_TIME *t, ASN1_GENERALIZEDTIME **out) |
124 | { | 124 | { |
125 | ASN1_GENERALIZEDTIME *ret; | 125 | ASN1_GENERALIZEDTIME *ret; |
126 | char *str; | 126 | char *str; |
127 | int newlen; | 127 | int newlen; |
@@ -129,20 +129,20 @@ ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(ASN1_TIME *t, ASN1_GENERALIZE | |||
129 | if (!ASN1_TIME_check(t)) return NULL; | 129 | if (!ASN1_TIME_check(t)) return NULL; |
130 | 130 | ||
131 | if (!out || !*out) | 131 | if (!out || !*out) |
132 | { | 132 | { |
133 | if (!(ret = ASN1_GENERALIZEDTIME_new ())) | 133 | if (!(ret = ASN1_GENERALIZEDTIME_new ())) |
134 | return NULL; | 134 | return NULL; |
135 | if (out) *out = ret; | 135 | if (out) *out = ret; |
136 | } | 136 | } |
137 | else ret = *out; | 137 | else ret = *out; |
138 | 138 | ||
139 | /* If already GeneralizedTime just copy across */ | 139 | /* If already GeneralizedTime just copy across */ |
140 | if (t->type == V_ASN1_GENERALIZEDTIME) | 140 | if (t->type == V_ASN1_GENERALIZEDTIME) |
141 | { | 141 | { |
142 | if(!ASN1_STRING_set(ret, t->data, t->length)) | 142 | if(!ASN1_STRING_set(ret, t->data, t->length)) |
143 | return NULL; | 143 | return NULL; |
144 | return ret; | 144 | return ret; |
145 | } | 145 | } |
146 | 146 | ||
147 | /* grow the string */ | 147 | /* grow the string */ |
148 | if (!ASN1_STRING_set(ret, NULL, t->length + 2)) | 148 | if (!ASN1_STRING_set(ret, NULL, t->length + 2)) |
@@ -157,10 +157,10 @@ ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(ASN1_TIME *t, ASN1_GENERALIZE | |||
157 | BUF_strlcat(str, (char *)t->data, newlen); | 157 | BUF_strlcat(str, (char *)t->data, newlen); |
158 | 158 | ||
159 | return ret; | 159 | return ret; |
160 | } | 160 | } |
161 | 161 | ||
162 | int ASN1_TIME_set_string(ASN1_TIME *s, const char *str) | 162 | int ASN1_TIME_set_string(ASN1_TIME *s, const char *str) |
163 | { | 163 | { |
164 | ASN1_TIME t; | 164 | ASN1_TIME t; |
165 | 165 | ||
166 | t.length = strlen(str); | 166 | t.length = strlen(str); |
@@ -170,14 +170,14 @@ int ASN1_TIME_set_string(ASN1_TIME *s, const char *str) | |||
170 | t.type = V_ASN1_UTCTIME; | 170 | t.type = V_ASN1_UTCTIME; |
171 | 171 | ||
172 | if (!ASN1_TIME_check(&t)) | 172 | if (!ASN1_TIME_check(&t)) |
173 | { | 173 | { |
174 | t.type = V_ASN1_GENERALIZEDTIME; | 174 | t.type = V_ASN1_GENERALIZEDTIME; |
175 | if (!ASN1_TIME_check(&t)) | 175 | if (!ASN1_TIME_check(&t)) |
176 | return 0; | 176 | return 0; |
177 | } | 177 | } |
178 | 178 | ||
179 | if (s && !ASN1_STRING_copy((ASN1_STRING *)s, (ASN1_STRING *)&t)) | 179 | if (s && !ASN1_STRING_copy((ASN1_STRING *)s, (ASN1_STRING *)&t)) |
180 | return 0; | 180 | return 0; |
181 | 181 | ||
182 | return 1; | 182 | return 1; |
183 | } | 183 | } |
diff --git a/src/lib/libcrypto/asn1/a_type.c b/src/lib/libcrypto/asn1/a_type.c index a45d2f9d12..c790d74d60 100644 --- a/src/lib/libcrypto/asn1/a_type.c +++ b/src/lib/libcrypto/asn1/a_type.c | |||
@@ -62,65 +62,65 @@ | |||
62 | #include <openssl/objects.h> | 62 | #include <openssl/objects.h> |
63 | 63 | ||
64 | int ASN1_TYPE_get(ASN1_TYPE *a) | 64 | int ASN1_TYPE_get(ASN1_TYPE *a) |
65 | { | 65 | { |
66 | if ((a->value.ptr != NULL) || (a->type == V_ASN1_NULL)) | 66 | if ((a->value.ptr != NULL) || (a->type == V_ASN1_NULL)) |
67 | return(a->type); | 67 | return(a->type); |
68 | else | 68 | else |
69 | return(0); | 69 | return(0); |
70 | } | 70 | } |
71 | 71 | ||
72 | void ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value) | 72 | void ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value) |
73 | { | 73 | { |
74 | if (a->value.ptr != NULL) | 74 | if (a->value.ptr != NULL) |
75 | { | 75 | { |
76 | ASN1_TYPE **tmp_a = &a; | 76 | ASN1_TYPE **tmp_a = &a; |
77 | ASN1_primitive_free((ASN1_VALUE **)tmp_a, NULL); | 77 | ASN1_primitive_free((ASN1_VALUE **)tmp_a, NULL); |
78 | } | 78 | } |
79 | a->type=type; | 79 | a->type=type; |
80 | if (type == V_ASN1_BOOLEAN) | 80 | if (type == V_ASN1_BOOLEAN) |
81 | a->value.boolean = value ? 0xff : 0; | 81 | a->value.boolean = value ? 0xff : 0; |
82 | else | 82 | else |
83 | a->value.ptr=value; | 83 | a->value.ptr=value; |
84 | } | 84 | } |
85 | 85 | ||
86 | int ASN1_TYPE_set1(ASN1_TYPE *a, int type, const void *value) | 86 | int ASN1_TYPE_set1(ASN1_TYPE *a, int type, const void *value) |
87 | { | 87 | { |
88 | if (!value || (type == V_ASN1_BOOLEAN)) | 88 | if (!value || (type == V_ASN1_BOOLEAN)) |
89 | { | 89 | { |
90 | void *p = (void *)value; | 90 | void *p = (void *)value; |
91 | ASN1_TYPE_set(a, type, p); | 91 | ASN1_TYPE_set(a, type, p); |
92 | } | 92 | } |
93 | else if (type == V_ASN1_OBJECT) | 93 | else if (type == V_ASN1_OBJECT) |
94 | { | 94 | { |
95 | ASN1_OBJECT *odup; | 95 | ASN1_OBJECT *odup; |
96 | odup = OBJ_dup(value); | 96 | odup = OBJ_dup(value); |
97 | if (!odup) | 97 | if (!odup) |
98 | return 0; | 98 | return 0; |
99 | ASN1_TYPE_set(a, type, odup); | 99 | ASN1_TYPE_set(a, type, odup); |
100 | } | 100 | } |
101 | else | 101 | else |
102 | { | 102 | { |
103 | ASN1_STRING *sdup; | 103 | ASN1_STRING *sdup; |
104 | sdup = ASN1_STRING_dup(value); | 104 | sdup = ASN1_STRING_dup(value); |
105 | if (!sdup) | 105 | if (!sdup) |
106 | return 0; | 106 | return 0; |
107 | ASN1_TYPE_set(a, type, sdup); | 107 | ASN1_TYPE_set(a, type, sdup); |
108 | } | ||
109 | return 1; | ||
110 | } | 108 | } |
109 | return 1; | ||
110 | } | ||
111 | 111 | ||
112 | IMPLEMENT_STACK_OF(ASN1_TYPE) | 112 | IMPLEMENT_STACK_OF(ASN1_TYPE) |
113 | IMPLEMENT_ASN1_SET_OF(ASN1_TYPE) | 113 | IMPLEMENT_ASN1_SET_OF(ASN1_TYPE) |
114 | 114 | ||
115 | /* Returns 0 if they are equal, != 0 otherwise. */ | 115 | /* Returns 0 if they are equal, != 0 otherwise. */ |
116 | int ASN1_TYPE_cmp(ASN1_TYPE *a, ASN1_TYPE *b) | 116 | int ASN1_TYPE_cmp(ASN1_TYPE *a, ASN1_TYPE *b) |
117 | { | 117 | { |
118 | int result = -1; | 118 | int result = -1; |
119 | 119 | ||
120 | if (!a || !b || a->type != b->type) return -1; | 120 | if (!a || !b || a->type != b->type) return -1; |
121 | 121 | ||
122 | switch (a->type) | 122 | switch (a->type) |
123 | { | 123 | { |
124 | case V_ASN1_OBJECT: | 124 | case V_ASN1_OBJECT: |
125 | result = OBJ_cmp(a->value.object, b->value.object); | 125 | result = OBJ_cmp(a->value.object, b->value.object); |
126 | break; | 126 | break; |
@@ -153,7 +153,7 @@ int ASN1_TYPE_cmp(ASN1_TYPE *a, ASN1_TYPE *b) | |||
153 | result = ASN1_STRING_cmp((ASN1_STRING *) a->value.ptr, | 153 | result = ASN1_STRING_cmp((ASN1_STRING *) a->value.ptr, |
154 | (ASN1_STRING *) b->value.ptr); | 154 | (ASN1_STRING *) b->value.ptr); |
155 | break; | 155 | break; |
156 | } | 156 | } |
157 | 157 | ||
158 | return result; | 158 | return result; |
159 | } | 159 | } |
diff --git a/src/lib/libcrypto/asn1/a_utctm.c b/src/lib/libcrypto/asn1/a_utctm.c index 0e7aca90a7..e75f2ecbb6 100644 --- a/src/lib/libcrypto/asn1/a_utctm.c +++ b/src/lib/libcrypto/asn1/a_utctm.c | |||
@@ -64,41 +64,41 @@ | |||
64 | 64 | ||
65 | #if 0 | 65 | #if 0 |
66 | int i2d_ASN1_UTCTIME(ASN1_UTCTIME *a, unsigned char **pp) | 66 | int i2d_ASN1_UTCTIME(ASN1_UTCTIME *a, unsigned char **pp) |
67 | { | 67 | { |
68 | return(i2d_ASN1_bytes((ASN1_STRING *)a,pp, | 68 | return(i2d_ASN1_bytes((ASN1_STRING *)a,pp, |
69 | V_ASN1_UTCTIME,V_ASN1_UNIVERSAL)); | 69 | V_ASN1_UTCTIME,V_ASN1_UNIVERSAL)); |
70 | } | 70 | } |
71 | 71 | ||
72 | 72 | ||
73 | ASN1_UTCTIME *d2i_ASN1_UTCTIME(ASN1_UTCTIME **a, unsigned char **pp, | 73 | ASN1_UTCTIME *d2i_ASN1_UTCTIME(ASN1_UTCTIME **a, unsigned char **pp, |
74 | long length) | 74 | long length) |
75 | { | 75 | { |
76 | ASN1_UTCTIME *ret=NULL; | 76 | ASN1_UTCTIME *ret=NULL; |
77 | 77 | ||
78 | ret=(ASN1_UTCTIME *)d2i_ASN1_bytes((ASN1_STRING **)a,pp,length, | 78 | ret=(ASN1_UTCTIME *)d2i_ASN1_bytes((ASN1_STRING **)a,pp,length, |
79 | V_ASN1_UTCTIME,V_ASN1_UNIVERSAL); | 79 | V_ASN1_UTCTIME,V_ASN1_UNIVERSAL); |
80 | if (ret == NULL) | 80 | if (ret == NULL) |
81 | { | 81 | { |
82 | ASN1err(ASN1_F_D2I_ASN1_UTCTIME,ERR_R_NESTED_ASN1_ERROR); | 82 | ASN1err(ASN1_F_D2I_ASN1_UTCTIME,ERR_R_NESTED_ASN1_ERROR); |
83 | return(NULL); | 83 | return(NULL); |
84 | } | 84 | } |
85 | if (!ASN1_UTCTIME_check(ret)) | 85 | if (!ASN1_UTCTIME_check(ret)) |
86 | { | 86 | { |
87 | ASN1err(ASN1_F_D2I_ASN1_UTCTIME,ASN1_R_INVALID_TIME_FORMAT); | 87 | ASN1err(ASN1_F_D2I_ASN1_UTCTIME,ASN1_R_INVALID_TIME_FORMAT); |
88 | goto err; | 88 | goto err; |
89 | } | 89 | } |
90 | 90 | ||
91 | return(ret); | 91 | return(ret); |
92 | err: | 92 | err: |
93 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) | 93 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) |
94 | M_ASN1_UTCTIME_free(ret); | 94 | M_ASN1_UTCTIME_free(ret); |
95 | return(NULL); | 95 | return(NULL); |
96 | } | 96 | } |
97 | 97 | ||
98 | #endif | 98 | #endif |
99 | 99 | ||
100 | int ASN1_UTCTIME_check(ASN1_UTCTIME *d) | 100 | int ASN1_UTCTIME_check(ASN1_UTCTIME *d) |
101 | { | 101 | { |
102 | static const int min[8]={ 0, 1, 1, 0, 0, 0, 0, 0}; | 102 | static const int min[8]={ 0, 1, 1, 0, 0, 0, 0, 0}; |
103 | static const int max[8]={99,12,31,23,59,59,12,59}; | 103 | static const int max[8]={99,12,31,23,59,59,12,59}; |
104 | char *a; | 104 | char *a; |
@@ -111,10 +111,10 @@ int ASN1_UTCTIME_check(ASN1_UTCTIME *d) | |||
111 | 111 | ||
112 | if (l < 11) goto err; | 112 | if (l < 11) goto err; |
113 | for (i=0; i<6; i++) | 113 | for (i=0; i<6; i++) |
114 | { | 114 | { |
115 | if ((i == 5) && ((a[o] == 'Z') || | 115 | if ((i == 5) && ((a[o] == 'Z') || |
116 | (a[o] == '+') || (a[o] == '-'))) | 116 | (a[o] == '+') || (a[o] == '-'))) |
117 | { i++; break; } | 117 | { i++; break; } |
118 | if ((a[o] < '0') || (a[o] > '9')) goto err; | 118 | if ((a[o] < '0') || (a[o] > '9')) goto err; |
119 | n= a[o]-'0'; | 119 | n= a[o]-'0'; |
120 | if (++o > l) goto err; | 120 | if (++o > l) goto err; |
@@ -124,15 +124,15 @@ int ASN1_UTCTIME_check(ASN1_UTCTIME *d) | |||
124 | if (++o > l) goto err; | 124 | if (++o > l) goto err; |
125 | 125 | ||
126 | if ((n < min[i]) || (n > max[i])) goto err; | 126 | if ((n < min[i]) || (n > max[i])) goto err; |
127 | } | 127 | } |
128 | if (a[o] == 'Z') | 128 | if (a[o] == 'Z') |
129 | o++; | 129 | o++; |
130 | else if ((a[o] == '+') || (a[o] == '-')) | 130 | else if ((a[o] == '+') || (a[o] == '-')) |
131 | { | 131 | { |
132 | o++; | 132 | o++; |
133 | if (o+4 > l) goto err; | 133 | if (o+4 > l) goto err; |
134 | for (i=6; i<8; i++) | 134 | for (i=6; i<8; i++) |
135 | { | 135 | { |
136 | if ((a[o] < '0') || (a[o] > '9')) goto err; | 136 | if ((a[o] < '0') || (a[o] > '9')) goto err; |
137 | n= a[o]-'0'; | 137 | n= a[o]-'0'; |
138 | o++; | 138 | o++; |
@@ -140,43 +140,43 @@ int ASN1_UTCTIME_check(ASN1_UTCTIME *d) | |||
140 | n=(n*10)+ a[o]-'0'; | 140 | n=(n*10)+ a[o]-'0'; |
141 | if ((n < min[i]) || (n > max[i])) goto err; | 141 | if ((n < min[i]) || (n > max[i])) goto err; |
142 | o++; | 142 | o++; |
143 | } | ||
144 | } | 143 | } |
144 | } | ||
145 | return(o == l); | 145 | return(o == l); |
146 | err: | 146 | err: |
147 | return(0); | 147 | return(0); |
148 | } | 148 | } |
149 | 149 | ||
150 | int ASN1_UTCTIME_set_string(ASN1_UTCTIME *s, const char *str) | 150 | int ASN1_UTCTIME_set_string(ASN1_UTCTIME *s, const char *str) |
151 | { | 151 | { |
152 | ASN1_UTCTIME t; | 152 | ASN1_UTCTIME t; |
153 | 153 | ||
154 | t.type=V_ASN1_UTCTIME; | 154 | t.type=V_ASN1_UTCTIME; |
155 | t.length=strlen(str); | 155 | t.length=strlen(str); |
156 | t.data=(unsigned char *)str; | 156 | t.data=(unsigned char *)str; |
157 | if (ASN1_UTCTIME_check(&t)) | 157 | if (ASN1_UTCTIME_check(&t)) |
158 | { | 158 | { |
159 | if (s != NULL) | 159 | if (s != NULL) |
160 | { | 160 | { |
161 | if (!ASN1_STRING_set((ASN1_STRING *)s, | 161 | if (!ASN1_STRING_set((ASN1_STRING *)s, |
162 | (unsigned char *)str,t.length)) | 162 | (unsigned char *)str,t.length)) |
163 | return 0; | 163 | return 0; |
164 | s->type = V_ASN1_UTCTIME; | 164 | s->type = V_ASN1_UTCTIME; |
165 | } | ||
166 | return(1); | ||
167 | } | 165 | } |
166 | return(1); | ||
167 | } | ||
168 | else | 168 | else |
169 | return(0); | 169 | return(0); |
170 | } | 170 | } |
171 | 171 | ||
172 | ASN1_UTCTIME *ASN1_UTCTIME_set(ASN1_UTCTIME *s, time_t t) | 172 | ASN1_UTCTIME *ASN1_UTCTIME_set(ASN1_UTCTIME *s, time_t t) |
173 | { | 173 | { |
174 | return ASN1_UTCTIME_adj(s, t, 0, 0); | 174 | return ASN1_UTCTIME_adj(s, t, 0, 0); |
175 | } | 175 | } |
176 | 176 | ||
177 | ASN1_UTCTIME *ASN1_UTCTIME_adj(ASN1_UTCTIME *s, time_t t, | 177 | ASN1_UTCTIME *ASN1_UTCTIME_adj(ASN1_UTCTIME *s, time_t t, |
178 | int offset_day, long offset_sec) | 178 | int offset_day, long offset_sec) |
179 | { | 179 | { |
180 | char *p; | 180 | char *p; |
181 | struct tm *ts; | 181 | struct tm *ts; |
182 | struct tm data; | 182 | struct tm data; |
@@ -192,38 +192,38 @@ ASN1_UTCTIME *ASN1_UTCTIME_adj(ASN1_UTCTIME *s, time_t t, | |||
192 | return(NULL); | 192 | return(NULL); |
193 | 193 | ||
194 | if (offset_day || offset_sec) | 194 | if (offset_day || offset_sec) |
195 | { | 195 | { |
196 | if (!OPENSSL_gmtime_adj(ts, offset_day, offset_sec)) | 196 | if (!OPENSSL_gmtime_adj(ts, offset_day, offset_sec)) |
197 | return NULL; | 197 | return NULL; |
198 | } | 198 | } |
199 | 199 | ||
200 | if((ts->tm_year < 50) || (ts->tm_year >= 150)) | 200 | if((ts->tm_year < 50) || (ts->tm_year >= 150)) |
201 | return NULL; | 201 | return NULL; |
202 | 202 | ||
203 | p=(char *)s->data; | 203 | p=(char *)s->data; |
204 | if ((p == NULL) || ((size_t)s->length < len)) | 204 | if ((p == NULL) || ((size_t)s->length < len)) |
205 | { | 205 | { |
206 | p=malloc(len); | 206 | p=malloc(len); |
207 | if (p == NULL) | 207 | if (p == NULL) |
208 | { | 208 | { |
209 | ASN1err(ASN1_F_ASN1_UTCTIME_ADJ,ERR_R_MALLOC_FAILURE); | 209 | ASN1err(ASN1_F_ASN1_UTCTIME_ADJ,ERR_R_MALLOC_FAILURE); |
210 | return(NULL); | 210 | return(NULL); |
211 | } | 211 | } |
212 | if (s->data != NULL) | 212 | if (s->data != NULL) |
213 | free(s->data); | 213 | free(s->data); |
214 | s->data=(unsigned char *)p; | 214 | s->data=(unsigned char *)p; |
215 | } | 215 | } |
216 | 216 | ||
217 | (void) snprintf(p,len,"%02d%02d%02d%02d%02d%02dZ",ts->tm_year%100, | 217 | (void) snprintf(p,len,"%02d%02d%02d%02d%02d%02dZ",ts->tm_year%100, |
218 | ts->tm_mon+1,ts->tm_mday,ts->tm_hour,ts->tm_min,ts->tm_sec); | 218 | ts->tm_mon+1,ts->tm_mday,ts->tm_hour,ts->tm_min,ts->tm_sec); |
219 | s->length=strlen(p); | 219 | s->length=strlen(p); |
220 | s->type=V_ASN1_UTCTIME; | 220 | s->type=V_ASN1_UTCTIME; |
221 | return(s); | 221 | return(s); |
222 | } | 222 | } |
223 | 223 | ||
224 | 224 | ||
225 | int ASN1_UTCTIME_cmp_time_t(const ASN1_UTCTIME *s, time_t t) | 225 | int ASN1_UTCTIME_cmp_time_t(const ASN1_UTCTIME *s, time_t t) |
226 | { | 226 | { |
227 | struct tm *tm; | 227 | struct tm *tm; |
228 | struct tm data; | 228 | struct tm data; |
229 | int offset; | 229 | int offset; |
@@ -234,11 +234,11 @@ int ASN1_UTCTIME_cmp_time_t(const ASN1_UTCTIME *s, time_t t) | |||
234 | if (s->data[12] == 'Z') | 234 | if (s->data[12] == 'Z') |
235 | offset=0; | 235 | offset=0; |
236 | else | 236 | else |
237 | { | 237 | { |
238 | offset = g2(s->data+13)*60+g2(s->data+15); | 238 | offset = g2(s->data+13)*60+g2(s->data+15); |
239 | if (s->data[12] == '-') | 239 | if (s->data[12] == '-') |
240 | offset = -offset; | 240 | offset = -offset; |
241 | } | 241 | } |
242 | 242 | ||
243 | t -= offset*60; /* FIXME: may overflow in extreme cases */ | 243 | t -= offset*60; /* FIXME: may overflow in extreme cases */ |
244 | 244 | ||
@@ -258,12 +258,12 @@ int ASN1_UTCTIME_cmp_time_t(const ASN1_UTCTIME *s, time_t t) | |||
258 | #undef return_cmp | 258 | #undef return_cmp |
259 | 259 | ||
260 | return 0; | 260 | return 0; |
261 | } | 261 | } |
262 | 262 | ||
263 | 263 | ||
264 | #if 0 | 264 | #if 0 |
265 | time_t ASN1_UTCTIME_get(const ASN1_UTCTIME *s) | 265 | time_t ASN1_UTCTIME_get(const ASN1_UTCTIME *s) |
266 | { | 266 | { |
267 | struct tm tm; | 267 | struct tm tm; |
268 | int offset; | 268 | int offset; |
269 | 269 | ||
@@ -281,11 +281,11 @@ time_t ASN1_UTCTIME_get(const ASN1_UTCTIME *s) | |||
281 | if(s->data[12] == 'Z') | 281 | if(s->data[12] == 'Z') |
282 | offset=0; | 282 | offset=0; |
283 | else | 283 | else |
284 | { | 284 | { |
285 | offset=g2(s->data+13)*60+g2(s->data+15); | 285 | offset=g2(s->data+13)*60+g2(s->data+15); |
286 | if(s->data[12] == '-') | 286 | if(s->data[12] == '-') |
287 | offset= -offset; | 287 | offset= -offset; |
288 | } | 288 | } |
289 | #undef g2 | 289 | #undef g2 |
290 | 290 | ||
291 | return mktime(&tm)-offset*60; /* FIXME: mktime assumes the current timezone | 291 | return mktime(&tm)-offset*60; /* FIXME: mktime assumes the current timezone |
@@ -296,5 +296,5 @@ time_t ASN1_UTCTIME_get(const ASN1_UTCTIME *s) | |||
296 | * non-standard. | 296 | * non-standard. |
297 | * Also time_t is inappropriate for general | 297 | * Also time_t is inappropriate for general |
298 | * UTC times because it may a 32 bit type. */ | 298 | * UTC times because it may a 32 bit type. */ |
299 | } | 299 | } |
300 | #endif | 300 | #endif |
diff --git a/src/lib/libcrypto/asn1/a_verify.c b/src/lib/libcrypto/asn1/a_verify.c index 8eca970be3..59c5b876b5 100644 --- a/src/lib/libcrypto/asn1/a_verify.c +++ b/src/lib/libcrypto/asn1/a_verify.c | |||
@@ -74,7 +74,7 @@ | |||
74 | 74 | ||
75 | int ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a, | 75 | int ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a, |
76 | ASN1_BIT_STRING *signature, void *asn, EVP_PKEY *pkey) | 76 | ASN1_BIT_STRING *signature, void *asn, EVP_PKEY *pkey) |
77 | { | 77 | { |
78 | EVP_MD_CTX ctx; | 78 | EVP_MD_CTX ctx; |
79 | unsigned char *buf_in=NULL; | 79 | unsigned char *buf_in=NULL; |
80 | int ret= -1,inl; | 80 | int ret= -1,inl; |
@@ -82,26 +82,26 @@ int ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a, | |||
82 | int mdnid, pknid; | 82 | int mdnid, pknid; |
83 | 83 | ||
84 | if (!pkey) | 84 | if (!pkey) |
85 | { | 85 | { |
86 | ASN1err(ASN1_F_ASN1_ITEM_VERIFY, ERR_R_PASSED_NULL_PARAMETER); | 86 | ASN1err(ASN1_F_ASN1_ITEM_VERIFY, ERR_R_PASSED_NULL_PARAMETER); |
87 | return -1; | 87 | return -1; |
88 | } | 88 | } |
89 | 89 | ||
90 | EVP_MD_CTX_init(&ctx); | 90 | EVP_MD_CTX_init(&ctx); |
91 | 91 | ||
92 | /* Convert signature OID into digest and public key OIDs */ | 92 | /* Convert signature OID into digest and public key OIDs */ |
93 | if (!OBJ_find_sigid_algs(OBJ_obj2nid(a->algorithm), &mdnid, &pknid)) | 93 | if (!OBJ_find_sigid_algs(OBJ_obj2nid(a->algorithm), &mdnid, &pknid)) |
94 | { | 94 | { |
95 | ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ASN1_R_UNKNOWN_SIGNATURE_ALGORITHM); | 95 | ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ASN1_R_UNKNOWN_SIGNATURE_ALGORITHM); |
96 | goto err; | 96 | goto err; |
97 | } | 97 | } |
98 | if (mdnid == NID_undef) | 98 | if (mdnid == NID_undef) |
99 | { | 99 | { |
100 | if (!pkey->ameth || !pkey->ameth->item_verify) | 100 | if (!pkey->ameth || !pkey->ameth->item_verify) |
101 | { | 101 | { |
102 | ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ASN1_R_UNKNOWN_SIGNATURE_ALGORITHM); | 102 | ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ASN1_R_UNKNOWN_SIGNATURE_ALGORITHM); |
103 | goto err; | 103 | goto err; |
104 | } | 104 | } |
105 | ret = pkey->ameth->item_verify(&ctx, it, asn, a, | 105 | ret = pkey->ameth->item_verify(&ctx, it, asn, a, |
106 | signature, pkey); | 106 | signature, pkey); |
107 | /* Return value of 2 means carry on, anything else means we | 107 | /* Return value of 2 means carry on, anything else means we |
@@ -111,58 +111,58 @@ int ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a, | |||
111 | if (ret != 2) | 111 | if (ret != 2) |
112 | goto err; | 112 | goto err; |
113 | ret = -1; | 113 | ret = -1; |
114 | } | 114 | } |
115 | else | 115 | else |
116 | { | 116 | { |
117 | const EVP_MD *type; | 117 | const EVP_MD *type; |
118 | type=EVP_get_digestbynid(mdnid); | 118 | type=EVP_get_digestbynid(mdnid); |
119 | if (type == NULL) | 119 | if (type == NULL) |
120 | { | 120 | { |
121 | ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM); | 121 | ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM); |
122 | goto err; | 122 | goto err; |
123 | } | 123 | } |
124 | 124 | ||
125 | /* Check public key OID matches public key type */ | 125 | /* Check public key OID matches public key type */ |
126 | if (EVP_PKEY_type(pknid) != pkey->ameth->pkey_id) | 126 | if (EVP_PKEY_type(pknid) != pkey->ameth->pkey_id) |
127 | { | 127 | { |
128 | ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ASN1_R_WRONG_PUBLIC_KEY_TYPE); | 128 | ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ASN1_R_WRONG_PUBLIC_KEY_TYPE); |
129 | goto err; | 129 | goto err; |
130 | } | 130 | } |
131 | 131 | ||
132 | if (!EVP_DigestVerifyInit(&ctx, NULL, type, NULL, pkey)) | 132 | if (!EVP_DigestVerifyInit(&ctx, NULL, type, NULL, pkey)) |
133 | { | 133 | { |
134 | ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ERR_R_EVP_LIB); | 134 | ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ERR_R_EVP_LIB); |
135 | ret=0; | 135 | ret=0; |
136 | goto err; | 136 | goto err; |
137 | } | ||
138 | |||
139 | } | 137 | } |
140 | 138 | ||
139 | } | ||
140 | |||
141 | inl = ASN1_item_i2d(asn, &buf_in, it); | 141 | inl = ASN1_item_i2d(asn, &buf_in, it); |
142 | 142 | ||
143 | if (buf_in == NULL) | 143 | if (buf_in == NULL) |
144 | { | 144 | { |
145 | ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ERR_R_MALLOC_FAILURE); | 145 | ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ERR_R_MALLOC_FAILURE); |
146 | goto err; | 146 | goto err; |
147 | } | 147 | } |
148 | 148 | ||
149 | if (!EVP_DigestVerifyUpdate(&ctx,buf_in,inl)) | 149 | if (!EVP_DigestVerifyUpdate(&ctx,buf_in,inl)) |
150 | { | 150 | { |
151 | ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ERR_R_EVP_LIB); | 151 | ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ERR_R_EVP_LIB); |
152 | ret=0; | 152 | ret=0; |
153 | goto err; | 153 | goto err; |
154 | } | 154 | } |
155 | 155 | ||
156 | OPENSSL_cleanse(buf_in,(unsigned int)inl); | 156 | OPENSSL_cleanse(buf_in,(unsigned int)inl); |
157 | free(buf_in); | 157 | free(buf_in); |
158 | 158 | ||
159 | if (EVP_DigestVerifyFinal(&ctx,signature->data, | 159 | if (EVP_DigestVerifyFinal(&ctx,signature->data, |
160 | (size_t)signature->length) <= 0) | 160 | (size_t)signature->length) <= 0) |
161 | { | 161 | { |
162 | ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ERR_R_EVP_LIB); | 162 | ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ERR_R_EVP_LIB); |
163 | ret=0; | 163 | ret=0; |
164 | goto err; | 164 | goto err; |
165 | } | 165 | } |
166 | /* we don't need to zero the 'ctx' because we just checked | 166 | /* we don't need to zero the 'ctx' because we just checked |
167 | * public information */ | 167 | * public information */ |
168 | /* memset(&ctx,0,sizeof(ctx)); */ | 168 | /* memset(&ctx,0,sizeof(ctx)); */ |
@@ -170,6 +170,6 @@ int ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a, | |||
170 | err: | 170 | err: |
171 | EVP_MD_CTX_cleanup(&ctx); | 171 | EVP_MD_CTX_cleanup(&ctx); |
172 | return(ret); | 172 | return(ret); |
173 | } | 173 | } |
174 | 174 | ||
175 | 175 | ||
diff --git a/src/lib/libcrypto/asn1/ameth_lib.c b/src/lib/libcrypto/asn1/ameth_lib.c index 228392f1e6..8f96e00c93 100644 --- a/src/lib/libcrypto/asn1/ameth_lib.c +++ b/src/lib/libcrypto/asn1/ameth_lib.c | |||
@@ -73,7 +73,7 @@ extern const EVP_PKEY_ASN1_METHOD cmac_asn1_meth; | |||
73 | 73 | ||
74 | /* Keep this sorted in type order !! */ | 74 | /* Keep this sorted in type order !! */ |
75 | static const EVP_PKEY_ASN1_METHOD *standard_methods[] = | 75 | static const EVP_PKEY_ASN1_METHOD *standard_methods[] = |
76 | { | 76 | { |
77 | #ifndef OPENSSL_NO_RSA | 77 | #ifndef OPENSSL_NO_RSA |
78 | &rsa_asn1_meths[0], | 78 | &rsa_asn1_meths[0], |
79 | &rsa_asn1_meths[1], | 79 | &rsa_asn1_meths[1], |
@@ -93,7 +93,7 @@ static const EVP_PKEY_ASN1_METHOD *standard_methods[] = | |||
93 | #endif | 93 | #endif |
94 | &hmac_asn1_meth, | 94 | &hmac_asn1_meth, |
95 | &cmac_asn1_meth | 95 | &cmac_asn1_meth |
96 | }; | 96 | }; |
97 | 97 | ||
98 | typedef int sk_cmp_fn_type(const char * const *a, const char * const *b); | 98 | typedef int sk_cmp_fn_type(const char * const *a, const char * const *b); |
99 | DECLARE_STACK_OF(EVP_PKEY_ASN1_METHOD) | 99 | DECLARE_STACK_OF(EVP_PKEY_ASN1_METHOD) |
@@ -103,7 +103,7 @@ static STACK_OF(EVP_PKEY_ASN1_METHOD) *app_methods = NULL; | |||
103 | 103 | ||
104 | #ifdef TEST | 104 | #ifdef TEST |
105 | void main() | 105 | void main() |
106 | { | 106 | { |
107 | int i; | 107 | int i; |
108 | for (i = 0; | 108 | for (i = 0; |
109 | i < sizeof(standard_methods)/sizeof(EVP_PKEY_ASN1_METHOD *); | 109 | i < sizeof(standard_methods)/sizeof(EVP_PKEY_ASN1_METHOD *); |
@@ -111,7 +111,7 @@ void main() | |||
111 | fprintf(stderr, "Number %d id=%d (%s)\n", i, | 111 | fprintf(stderr, "Number %d id=%d (%s)\n", i, |
112 | standard_methods[i]->pkey_id, | 112 | standard_methods[i]->pkey_id, |
113 | OBJ_nid2sn(standard_methods[i]->pkey_id)); | 113 | OBJ_nid2sn(standard_methods[i]->pkey_id)); |
114 | } | 114 | } |
115 | #endif | 115 | #endif |
116 | 116 | ||
117 | DECLARE_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_ASN1_METHOD *, | 117 | DECLARE_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_ASN1_METHOD *, |
@@ -119,23 +119,23 @@ DECLARE_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_ASN1_METHOD *, | |||
119 | 119 | ||
120 | static int ameth_cmp(const EVP_PKEY_ASN1_METHOD * const *a, | 120 | static int ameth_cmp(const EVP_PKEY_ASN1_METHOD * const *a, |
121 | const EVP_PKEY_ASN1_METHOD * const *b) | 121 | const EVP_PKEY_ASN1_METHOD * const *b) |
122 | { | 122 | { |
123 | return ((*a)->pkey_id - (*b)->pkey_id); | 123 | return ((*a)->pkey_id - (*b)->pkey_id); |
124 | } | 124 | } |
125 | 125 | ||
126 | IMPLEMENT_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_ASN1_METHOD *, | 126 | IMPLEMENT_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_ASN1_METHOD *, |
127 | const EVP_PKEY_ASN1_METHOD *, ameth); | 127 | const EVP_PKEY_ASN1_METHOD *, ameth); |
128 | 128 | ||
129 | int EVP_PKEY_asn1_get_count(void) | 129 | int EVP_PKEY_asn1_get_count(void) |
130 | { | 130 | { |
131 | int num = sizeof(standard_methods)/sizeof(EVP_PKEY_ASN1_METHOD *); | 131 | int num = sizeof(standard_methods)/sizeof(EVP_PKEY_ASN1_METHOD *); |
132 | if (app_methods) | 132 | if (app_methods) |
133 | num += sk_EVP_PKEY_ASN1_METHOD_num(app_methods); | 133 | num += sk_EVP_PKEY_ASN1_METHOD_num(app_methods); |
134 | return num; | 134 | return num; |
135 | } | 135 | } |
136 | 136 | ||
137 | const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_get0(int idx) | 137 | const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_get0(int idx) |
138 | { | 138 | { |
139 | int num = sizeof(standard_methods)/sizeof(EVP_PKEY_ASN1_METHOD *); | 139 | int num = sizeof(standard_methods)/sizeof(EVP_PKEY_ASN1_METHOD *); |
140 | if (idx < 0) | 140 | if (idx < 0) |
141 | return NULL; | 141 | return NULL; |
@@ -143,27 +143,27 @@ const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_get0(int idx) | |||
143 | return standard_methods[idx]; | 143 | return standard_methods[idx]; |
144 | idx -= num; | 144 | idx -= num; |
145 | return sk_EVP_PKEY_ASN1_METHOD_value(app_methods, idx); | 145 | return sk_EVP_PKEY_ASN1_METHOD_value(app_methods, idx); |
146 | } | 146 | } |
147 | 147 | ||
148 | static const EVP_PKEY_ASN1_METHOD *pkey_asn1_find(int type) | 148 | static const EVP_PKEY_ASN1_METHOD *pkey_asn1_find(int type) |
149 | { | 149 | { |
150 | EVP_PKEY_ASN1_METHOD tmp; | 150 | EVP_PKEY_ASN1_METHOD tmp; |
151 | const EVP_PKEY_ASN1_METHOD *t = &tmp, **ret; | 151 | const EVP_PKEY_ASN1_METHOD *t = &tmp, **ret; |
152 | tmp.pkey_id = type; | 152 | tmp.pkey_id = type; |
153 | if (app_methods) | 153 | if (app_methods) |
154 | { | 154 | { |
155 | int idx; | 155 | int idx; |
156 | idx = sk_EVP_PKEY_ASN1_METHOD_find(app_methods, &tmp); | 156 | idx = sk_EVP_PKEY_ASN1_METHOD_find(app_methods, &tmp); |
157 | if (idx >= 0) | 157 | if (idx >= 0) |
158 | return sk_EVP_PKEY_ASN1_METHOD_value(app_methods, idx); | 158 | return sk_EVP_PKEY_ASN1_METHOD_value(app_methods, idx); |
159 | } | 159 | } |
160 | ret = OBJ_bsearch_ameth(&t, standard_methods, | 160 | ret = OBJ_bsearch_ameth(&t, standard_methods, |
161 | sizeof(standard_methods) | 161 | sizeof(standard_methods) |
162 | /sizeof(EVP_PKEY_ASN1_METHOD *)); | 162 | /sizeof(EVP_PKEY_ASN1_METHOD *)); |
163 | if (!ret || !*ret) | 163 | if (!ret || !*ret) |
164 | return NULL; | 164 | return NULL; |
165 | return *ret; | 165 | return *ret; |
166 | } | 166 | } |
167 | 167 | ||
168 | /* Find an implementation of an ASN1 algorithm. If 'pe' is not NULL | 168 | /* Find an implementation of an ASN1 algorithm. If 'pe' is not NULL |
169 | * also search through engines and set *pe to a functional reference | 169 | * also search through engines and set *pe to a functional reference |
@@ -172,47 +172,47 @@ static const EVP_PKEY_ASN1_METHOD *pkey_asn1_find(int type) | |||
172 | */ | 172 | */ |
173 | 173 | ||
174 | const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_find(ENGINE **pe, int type) | 174 | const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_find(ENGINE **pe, int type) |
175 | { | 175 | { |
176 | const EVP_PKEY_ASN1_METHOD *t; | 176 | const EVP_PKEY_ASN1_METHOD *t; |
177 | 177 | ||
178 | for (;;) | 178 | for (;;) |
179 | { | 179 | { |
180 | t = pkey_asn1_find(type); | 180 | t = pkey_asn1_find(type); |
181 | if (!t || !(t->pkey_flags & ASN1_PKEY_ALIAS)) | 181 | if (!t || !(t->pkey_flags & ASN1_PKEY_ALIAS)) |
182 | break; | 182 | break; |
183 | type = t->pkey_base_id; | 183 | type = t->pkey_base_id; |
184 | } | 184 | } |
185 | if (pe) | 185 | if (pe) |
186 | { | 186 | { |
187 | #ifndef OPENSSL_NO_ENGINE | 187 | #ifndef OPENSSL_NO_ENGINE |
188 | ENGINE *e; | 188 | ENGINE *e; |
189 | /* type will contain the final unaliased type */ | 189 | /* type will contain the final unaliased type */ |
190 | e = ENGINE_get_pkey_asn1_meth_engine(type); | 190 | e = ENGINE_get_pkey_asn1_meth_engine(type); |
191 | if (e) | 191 | if (e) |
192 | { | 192 | { |
193 | *pe = e; | 193 | *pe = e; |
194 | return ENGINE_get_pkey_asn1_meth(e, type); | 194 | return ENGINE_get_pkey_asn1_meth(e, type); |
195 | } | 195 | } |
196 | #endif | 196 | #endif |
197 | *pe = NULL; | 197 | *pe = NULL; |
198 | } | ||
199 | return t; | ||
200 | } | 198 | } |
199 | return t; | ||
200 | } | ||
201 | 201 | ||
202 | const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_find_str(ENGINE **pe, | 202 | const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_find_str(ENGINE **pe, |
203 | const char *str, int len) | 203 | const char *str, int len) |
204 | { | 204 | { |
205 | int i; | 205 | int i; |
206 | const EVP_PKEY_ASN1_METHOD *ameth; | 206 | const EVP_PKEY_ASN1_METHOD *ameth; |
207 | if (len == -1) | 207 | if (len == -1) |
208 | len = strlen(str); | 208 | len = strlen(str); |
209 | if (pe) | 209 | if (pe) |
210 | { | 210 | { |
211 | #ifndef OPENSSL_NO_ENGINE | 211 | #ifndef OPENSSL_NO_ENGINE |
212 | ENGINE *e; | 212 | ENGINE *e; |
213 | ameth = ENGINE_pkey_asn1_find_str(&e, str, len); | 213 | ameth = ENGINE_pkey_asn1_find_str(&e, str, len); |
214 | if (ameth) | 214 | if (ameth) |
215 | { | 215 | { |
216 | /* Convert structural into | 216 | /* Convert structural into |
217 | * functional reference | 217 | * functional reference |
218 | */ | 218 | */ |
@@ -221,50 +221,50 @@ const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_find_str(ENGINE **pe, | |||
221 | ENGINE_free(e); | 221 | ENGINE_free(e); |
222 | *pe = e; | 222 | *pe = e; |
223 | return ameth; | 223 | return ameth; |
224 | } | 224 | } |
225 | #endif | 225 | #endif |
226 | *pe = NULL; | 226 | *pe = NULL; |
227 | } | 227 | } |
228 | for (i = 0; i < EVP_PKEY_asn1_get_count(); i++) | 228 | for (i = 0; i < EVP_PKEY_asn1_get_count(); i++) |
229 | { | 229 | { |
230 | ameth = EVP_PKEY_asn1_get0(i); | 230 | ameth = EVP_PKEY_asn1_get0(i); |
231 | if (ameth->pkey_flags & ASN1_PKEY_ALIAS) | 231 | if (ameth->pkey_flags & ASN1_PKEY_ALIAS) |
232 | continue; | 232 | continue; |
233 | if (((int)strlen(ameth->pem_str) == len) && | 233 | if (((int)strlen(ameth->pem_str) == len) && |
234 | !strncasecmp(ameth->pem_str, str, len)) | 234 | !strncasecmp(ameth->pem_str, str, len)) |
235 | return ameth; | 235 | return ameth; |
236 | } | ||
237 | return NULL; | ||
238 | } | 236 | } |
237 | return NULL; | ||
238 | } | ||
239 | 239 | ||
240 | int EVP_PKEY_asn1_add0(const EVP_PKEY_ASN1_METHOD *ameth) | 240 | int EVP_PKEY_asn1_add0(const EVP_PKEY_ASN1_METHOD *ameth) |
241 | { | 241 | { |
242 | if (app_methods == NULL) | 242 | if (app_methods == NULL) |
243 | { | 243 | { |
244 | app_methods = sk_EVP_PKEY_ASN1_METHOD_new(ameth_cmp); | 244 | app_methods = sk_EVP_PKEY_ASN1_METHOD_new(ameth_cmp); |
245 | if (!app_methods) | 245 | if (!app_methods) |
246 | return 0; | 246 | return 0; |
247 | } | 247 | } |
248 | if (!sk_EVP_PKEY_ASN1_METHOD_push(app_methods, ameth)) | 248 | if (!sk_EVP_PKEY_ASN1_METHOD_push(app_methods, ameth)) |
249 | return 0; | 249 | return 0; |
250 | sk_EVP_PKEY_ASN1_METHOD_sort(app_methods); | 250 | sk_EVP_PKEY_ASN1_METHOD_sort(app_methods); |
251 | return 1; | 251 | return 1; |
252 | } | 252 | } |
253 | 253 | ||
254 | int EVP_PKEY_asn1_add_alias(int to, int from) | 254 | int EVP_PKEY_asn1_add_alias(int to, int from) |
255 | { | 255 | { |
256 | EVP_PKEY_ASN1_METHOD *ameth; | 256 | EVP_PKEY_ASN1_METHOD *ameth; |
257 | ameth = EVP_PKEY_asn1_new(from, ASN1_PKEY_ALIAS, NULL, NULL); | 257 | ameth = EVP_PKEY_asn1_new(from, ASN1_PKEY_ALIAS, NULL, NULL); |
258 | if (!ameth) | 258 | if (!ameth) |
259 | return 0; | 259 | return 0; |
260 | ameth->pkey_base_id = to; | 260 | ameth->pkey_base_id = to; |
261 | return EVP_PKEY_asn1_add0(ameth); | 261 | return EVP_PKEY_asn1_add0(ameth); |
262 | } | 262 | } |
263 | 263 | ||
264 | int EVP_PKEY_asn1_get0_info(int *ppkey_id, int *ppkey_base_id, int *ppkey_flags, | 264 | int EVP_PKEY_asn1_get0_info(int *ppkey_id, int *ppkey_base_id, int *ppkey_flags, |
265 | const char **pinfo, const char **ppem_str, | 265 | const char **pinfo, const char **ppem_str, |
266 | const EVP_PKEY_ASN1_METHOD *ameth) | 266 | const EVP_PKEY_ASN1_METHOD *ameth) |
267 | { | 267 | { |
268 | if (!ameth) | 268 | if (!ameth) |
269 | return 0; | 269 | return 0; |
270 | if (ppkey_id) | 270 | if (ppkey_id) |
@@ -278,16 +278,16 @@ int EVP_PKEY_asn1_get0_info(int *ppkey_id, int *ppkey_base_id, int *ppkey_flags, | |||
278 | if (ppem_str) | 278 | if (ppem_str) |
279 | *ppem_str = ameth->pem_str; | 279 | *ppem_str = ameth->pem_str; |
280 | return 1; | 280 | return 1; |
281 | } | 281 | } |
282 | 282 | ||
283 | const EVP_PKEY_ASN1_METHOD* EVP_PKEY_get0_asn1(EVP_PKEY *pkey) | 283 | const EVP_PKEY_ASN1_METHOD* EVP_PKEY_get0_asn1(EVP_PKEY *pkey) |
284 | { | 284 | { |
285 | return pkey->ameth; | 285 | return pkey->ameth; |
286 | } | 286 | } |
287 | 287 | ||
288 | EVP_PKEY_ASN1_METHOD* EVP_PKEY_asn1_new(int id, int flags, | 288 | EVP_PKEY_ASN1_METHOD* EVP_PKEY_asn1_new(int id, int flags, |
289 | const char *pem_str, const char *info) | 289 | const char *pem_str, const char *info) |
290 | { | 290 | { |
291 | EVP_PKEY_ASN1_METHOD *ameth; | 291 | EVP_PKEY_ASN1_METHOD *ameth; |
292 | ameth = malloc(sizeof(EVP_PKEY_ASN1_METHOD)); | 292 | ameth = malloc(sizeof(EVP_PKEY_ASN1_METHOD)); |
293 | if (!ameth) | 293 | if (!ameth) |
@@ -300,20 +300,20 @@ EVP_PKEY_ASN1_METHOD* EVP_PKEY_asn1_new(int id, int flags, | |||
300 | ameth->pkey_flags = flags | ASN1_PKEY_DYNAMIC; | 300 | ameth->pkey_flags = flags | ASN1_PKEY_DYNAMIC; |
301 | 301 | ||
302 | if (info) | 302 | if (info) |
303 | { | 303 | { |
304 | ameth->info = BUF_strdup(info); | 304 | ameth->info = BUF_strdup(info); |
305 | if (!ameth->info) | 305 | if (!ameth->info) |
306 | goto err; | 306 | goto err; |
307 | } | 307 | } |
308 | else | 308 | else |
309 | ameth->info = NULL; | 309 | ameth->info = NULL; |
310 | 310 | ||
311 | if (pem_str) | 311 | if (pem_str) |
312 | { | 312 | { |
313 | ameth->pem_str = BUF_strdup(pem_str); | 313 | ameth->pem_str = BUF_strdup(pem_str); |
314 | if (!ameth->pem_str) | 314 | if (!ameth->pem_str) |
315 | goto err; | 315 | goto err; |
316 | } | 316 | } |
317 | else | 317 | else |
318 | ameth->pem_str = NULL; | 318 | ameth->pem_str = NULL; |
319 | 319 | ||
@@ -352,11 +352,11 @@ EVP_PKEY_ASN1_METHOD* EVP_PKEY_asn1_new(int id, int flags, | |||
352 | EVP_PKEY_asn1_free(ameth); | 352 | EVP_PKEY_asn1_free(ameth); |
353 | return NULL; | 353 | return NULL; |
354 | 354 | ||
355 | } | 355 | } |
356 | 356 | ||
357 | void EVP_PKEY_asn1_copy(EVP_PKEY_ASN1_METHOD *dst, | 357 | void EVP_PKEY_asn1_copy(EVP_PKEY_ASN1_METHOD *dst, |
358 | const EVP_PKEY_ASN1_METHOD *src) | 358 | const EVP_PKEY_ASN1_METHOD *src) |
359 | { | 359 | { |
360 | 360 | ||
361 | dst->pub_decode = src->pub_decode; | 361 | dst->pub_decode = src->pub_decode; |
362 | dst->pub_encode = src->pub_encode; | 362 | dst->pub_encode = src->pub_encode; |
@@ -386,19 +386,19 @@ void EVP_PKEY_asn1_copy(EVP_PKEY_ASN1_METHOD *dst, | |||
386 | dst->item_sign = src->item_sign; | 386 | dst->item_sign = src->item_sign; |
387 | dst->item_verify = src->item_verify; | 387 | dst->item_verify = src->item_verify; |
388 | 388 | ||
389 | } | 389 | } |
390 | 390 | ||
391 | void EVP_PKEY_asn1_free(EVP_PKEY_ASN1_METHOD *ameth) | 391 | void EVP_PKEY_asn1_free(EVP_PKEY_ASN1_METHOD *ameth) |
392 | { | 392 | { |
393 | if (ameth && (ameth->pkey_flags & ASN1_PKEY_DYNAMIC)) | 393 | if (ameth && (ameth->pkey_flags & ASN1_PKEY_DYNAMIC)) |
394 | { | 394 | { |
395 | if (ameth->pem_str) | 395 | if (ameth->pem_str) |
396 | free(ameth->pem_str); | 396 | free(ameth->pem_str); |
397 | if (ameth->info) | 397 | if (ameth->info) |
398 | free(ameth->info); | 398 | free(ameth->info); |
399 | free(ameth); | 399 | free(ameth); |
400 | } | ||
401 | } | 400 | } |
401 | } | ||
402 | 402 | ||
403 | void EVP_PKEY_asn1_set_public(EVP_PKEY_ASN1_METHOD *ameth, | 403 | void EVP_PKEY_asn1_set_public(EVP_PKEY_ASN1_METHOD *ameth, |
404 | int (*pub_decode)(EVP_PKEY *pk, X509_PUBKEY *pub), | 404 | int (*pub_decode)(EVP_PKEY *pk, X509_PUBKEY *pub), |
@@ -408,25 +408,25 @@ void EVP_PKEY_asn1_set_public(EVP_PKEY_ASN1_METHOD *ameth, | |||
408 | ASN1_PCTX *pctx), | 408 | ASN1_PCTX *pctx), |
409 | int (*pkey_size)(const EVP_PKEY *pk), | 409 | int (*pkey_size)(const EVP_PKEY *pk), |
410 | int (*pkey_bits)(const EVP_PKEY *pk)) | 410 | int (*pkey_bits)(const EVP_PKEY *pk)) |
411 | { | 411 | { |
412 | ameth->pub_decode = pub_decode; | 412 | ameth->pub_decode = pub_decode; |
413 | ameth->pub_encode = pub_encode; | 413 | ameth->pub_encode = pub_encode; |
414 | ameth->pub_cmp = pub_cmp; | 414 | ameth->pub_cmp = pub_cmp; |
415 | ameth->pub_print = pub_print; | 415 | ameth->pub_print = pub_print; |
416 | ameth->pkey_size = pkey_size; | 416 | ameth->pkey_size = pkey_size; |
417 | ameth->pkey_bits = pkey_bits; | 417 | ameth->pkey_bits = pkey_bits; |
418 | } | 418 | } |
419 | 419 | ||
420 | void EVP_PKEY_asn1_set_private(EVP_PKEY_ASN1_METHOD *ameth, | 420 | void EVP_PKEY_asn1_set_private(EVP_PKEY_ASN1_METHOD *ameth, |
421 | int (*priv_decode)(EVP_PKEY *pk, PKCS8_PRIV_KEY_INFO *p8inf), | 421 | int (*priv_decode)(EVP_PKEY *pk, PKCS8_PRIV_KEY_INFO *p8inf), |
422 | int (*priv_encode)(PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pk), | 422 | int (*priv_encode)(PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pk), |
423 | int (*priv_print)(BIO *out, const EVP_PKEY *pkey, int indent, | 423 | int (*priv_print)(BIO *out, const EVP_PKEY *pkey, int indent, |
424 | ASN1_PCTX *pctx)) | 424 | ASN1_PCTX *pctx)) |
425 | { | 425 | { |
426 | ameth->priv_decode = priv_decode; | 426 | ameth->priv_decode = priv_decode; |
427 | ameth->priv_encode = priv_encode; | 427 | ameth->priv_encode = priv_encode; |
428 | ameth->priv_print = priv_print; | 428 | ameth->priv_print = priv_print; |
429 | } | 429 | } |
430 | 430 | ||
431 | void EVP_PKEY_asn1_set_param(EVP_PKEY_ASN1_METHOD *ameth, | 431 | void EVP_PKEY_asn1_set_param(EVP_PKEY_ASN1_METHOD *ameth, |
432 | int (*param_decode)(EVP_PKEY *pkey, | 432 | int (*param_decode)(EVP_PKEY *pkey, |
@@ -437,24 +437,24 @@ void EVP_PKEY_asn1_set_param(EVP_PKEY_ASN1_METHOD *ameth, | |||
437 | int (*param_cmp)(const EVP_PKEY *a, const EVP_PKEY *b), | 437 | int (*param_cmp)(const EVP_PKEY *a, const EVP_PKEY *b), |
438 | int (*param_print)(BIO *out, const EVP_PKEY *pkey, int indent, | 438 | int (*param_print)(BIO *out, const EVP_PKEY *pkey, int indent, |
439 | ASN1_PCTX *pctx)) | 439 | ASN1_PCTX *pctx)) |
440 | { | 440 | { |
441 | ameth->param_decode = param_decode; | 441 | ameth->param_decode = param_decode; |
442 | ameth->param_encode = param_encode; | 442 | ameth->param_encode = param_encode; |
443 | ameth->param_missing = param_missing; | 443 | ameth->param_missing = param_missing; |
444 | ameth->param_copy = param_copy; | 444 | ameth->param_copy = param_copy; |
445 | ameth->param_cmp = param_cmp; | 445 | ameth->param_cmp = param_cmp; |
446 | ameth->param_print = param_print; | 446 | ameth->param_print = param_print; |
447 | } | 447 | } |
448 | 448 | ||
449 | void EVP_PKEY_asn1_set_free(EVP_PKEY_ASN1_METHOD *ameth, | 449 | void EVP_PKEY_asn1_set_free(EVP_PKEY_ASN1_METHOD *ameth, |
450 | void (*pkey_free)(EVP_PKEY *pkey)) | 450 | void (*pkey_free)(EVP_PKEY *pkey)) |
451 | { | 451 | { |
452 | ameth->pkey_free = pkey_free; | 452 | ameth->pkey_free = pkey_free; |
453 | } | 453 | } |
454 | 454 | ||
455 | void EVP_PKEY_asn1_set_ctrl(EVP_PKEY_ASN1_METHOD *ameth, | 455 | void EVP_PKEY_asn1_set_ctrl(EVP_PKEY_ASN1_METHOD *ameth, |
456 | int (*pkey_ctrl)(EVP_PKEY *pkey, int op, | 456 | int (*pkey_ctrl)(EVP_PKEY *pkey, int op, |
457 | long arg1, void *arg2)) | 457 | long arg1, void *arg2)) |
458 | { | 458 | { |
459 | ameth->pkey_ctrl = pkey_ctrl; | 459 | ameth->pkey_ctrl = pkey_ctrl; |
460 | } | 460 | } |
diff --git a/src/lib/libcrypto/asn1/asn1_err.c b/src/lib/libcrypto/asn1/asn1_err.c index aa60203ba8..582f613744 100644 --- a/src/lib/libcrypto/asn1/asn1_err.c +++ b/src/lib/libcrypto/asn1/asn1_err.c | |||
@@ -69,7 +69,7 @@ | |||
69 | #define ERR_REASON(reason) ERR_PACK(ERR_LIB_ASN1,0,reason) | 69 | #define ERR_REASON(reason) ERR_PACK(ERR_LIB_ASN1,0,reason) |
70 | 70 | ||
71 | static ERR_STRING_DATA ASN1_str_functs[]= | 71 | static ERR_STRING_DATA ASN1_str_functs[]= |
72 | { | 72 | { |
73 | {ERR_FUNC(ASN1_F_A2D_ASN1_OBJECT), "a2d_ASN1_OBJECT"}, | 73 | {ERR_FUNC(ASN1_F_A2D_ASN1_OBJECT), "a2d_ASN1_OBJECT"}, |
74 | {ERR_FUNC(ASN1_F_A2I_ASN1_ENUMERATED), "a2i_ASN1_ENUMERATED"}, | 74 | {ERR_FUNC(ASN1_F_A2I_ASN1_ENUMERATED), "a2i_ASN1_ENUMERATED"}, |
75 | {ERR_FUNC(ASN1_F_A2I_ASN1_INTEGER), "a2i_ASN1_INTEGER"}, | 75 | {ERR_FUNC(ASN1_F_A2I_ASN1_INTEGER), "a2i_ASN1_INTEGER"}, |
@@ -192,10 +192,10 @@ static ERR_STRING_DATA ASN1_str_functs[]= | |||
192 | {ERR_FUNC(ASN1_F_X509_NEW), "X509_NEW"}, | 192 | {ERR_FUNC(ASN1_F_X509_NEW), "X509_NEW"}, |
193 | {ERR_FUNC(ASN1_F_X509_PKEY_NEW), "X509_PKEY_new"}, | 193 | {ERR_FUNC(ASN1_F_X509_PKEY_NEW), "X509_PKEY_new"}, |
194 | {0,NULL} | 194 | {0,NULL} |
195 | }; | 195 | }; |
196 | 196 | ||
197 | static ERR_STRING_DATA ASN1_str_reasons[]= | 197 | static ERR_STRING_DATA ASN1_str_reasons[]= |
198 | { | 198 | { |
199 | {ERR_REASON(ASN1_R_ADDING_OBJECT) ,"adding object"}, | 199 | {ERR_REASON(ASN1_R_ADDING_OBJECT) ,"adding object"}, |
200 | {ERR_REASON(ASN1_R_ASN1_PARSE_ERROR) ,"asn1 parse error"}, | 200 | {ERR_REASON(ASN1_R_ASN1_PARSE_ERROR) ,"asn1 parse error"}, |
201 | {ERR_REASON(ASN1_R_ASN1_SIG_PARSE_ERROR) ,"asn1 sig parse error"}, | 201 | {ERR_REASON(ASN1_R_ASN1_SIG_PARSE_ERROR) ,"asn1 sig parse error"}, |
@@ -315,18 +315,18 @@ static ERR_STRING_DATA ASN1_str_reasons[]= | |||
315 | {ERR_REASON(ASN1_R_WRONG_TAG) ,"wrong tag"}, | 315 | {ERR_REASON(ASN1_R_WRONG_TAG) ,"wrong tag"}, |
316 | {ERR_REASON(ASN1_R_WRONG_TYPE) ,"wrong type"}, | 316 | {ERR_REASON(ASN1_R_WRONG_TYPE) ,"wrong type"}, |
317 | {0,NULL} | 317 | {0,NULL} |
318 | }; | 318 | }; |
319 | 319 | ||
320 | #endif | 320 | #endif |
321 | 321 | ||
322 | void ERR_load_ASN1_strings(void) | 322 | void ERR_load_ASN1_strings(void) |
323 | { | 323 | { |
324 | #ifndef OPENSSL_NO_ERR | 324 | #ifndef OPENSSL_NO_ERR |
325 | 325 | ||
326 | if (ERR_func_error_string(ASN1_str_functs[0].error) == NULL) | 326 | if (ERR_func_error_string(ASN1_str_functs[0].error) == NULL) |
327 | { | 327 | { |
328 | ERR_load_strings(0,ASN1_str_functs); | 328 | ERR_load_strings(0,ASN1_str_functs); |
329 | ERR_load_strings(0,ASN1_str_reasons); | 329 | ERR_load_strings(0,ASN1_str_reasons); |
330 | } | ||
331 | #endif | ||
332 | } | 330 | } |
331 | #endif | ||
332 | } | ||
diff --git a/src/lib/libcrypto/asn1/asn1_gen.c b/src/lib/libcrypto/asn1/asn1_gen.c index 8194beeb30..f78aac7148 100644 --- a/src/lib/libcrypto/asn1/asn1_gen.c +++ b/src/lib/libcrypto/asn1/asn1_gen.c | |||
@@ -70,7 +70,7 @@ | |||
70 | #define ASN1_GEN_FLAG_SETWRAP (ASN1_GEN_FLAG|7) | 70 | #define ASN1_GEN_FLAG_SETWRAP (ASN1_GEN_FLAG|7) |
71 | #define ASN1_GEN_FLAG_FORMAT (ASN1_GEN_FLAG|8) | 71 | #define ASN1_GEN_FLAG_FORMAT (ASN1_GEN_FLAG|8) |
72 | 72 | ||
73 | #define ASN1_GEN_STR(str,val) {str, sizeof(str) - 1, val} | 73 | #define ASN1_GEN_STR(str,val){str, sizeof(str) - 1, val} |
74 | 74 | ||
75 | #define ASN1_FLAG_EXP_MAX 20 | 75 | #define ASN1_FLAG_EXP_MAX 20 |
76 | 76 | ||
@@ -87,23 +87,23 @@ | |||
87 | 87 | ||
88 | 88 | ||
89 | struct tag_name_st | 89 | struct tag_name_st |
90 | { | 90 | { |
91 | const char *strnam; | 91 | const char *strnam; |
92 | int len; | 92 | int len; |
93 | int tag; | 93 | int tag; |
94 | }; | 94 | }; |
95 | 95 | ||
96 | typedef struct | 96 | typedef struct |
97 | { | 97 | { |
98 | int exp_tag; | 98 | int exp_tag; |
99 | int exp_class; | 99 | int exp_class; |
100 | int exp_constructed; | 100 | int exp_constructed; |
101 | int exp_pad; | 101 | int exp_pad; |
102 | long exp_len; | 102 | long exp_len; |
103 | } tag_exp_type; | 103 | } tag_exp_type; |
104 | 104 | ||
105 | typedef struct | 105 | typedef struct |
106 | { | 106 | { |
107 | int imp_tag; | 107 | int imp_tag; |
108 | int imp_class; | 108 | int imp_class; |
109 | int utype; | 109 | int utype; |
@@ -111,7 +111,7 @@ typedef struct | |||
111 | const char *str; | 111 | const char *str; |
112 | tag_exp_type exp_list[ASN1_FLAG_EXP_MAX]; | 112 | tag_exp_type exp_list[ASN1_FLAG_EXP_MAX]; |
113 | int exp_count; | 113 | int exp_count; |
114 | } tag_exp_arg; | 114 | } tag_exp_arg; |
115 | 115 | ||
116 | static int bitstr_cb(const char *elem, int len, void *bitstr); | 116 | static int bitstr_cb(const char *elem, int len, void *bitstr); |
117 | static int asn1_cb(const char *elem, int len, void *bitstr); | 117 | static int asn1_cb(const char *elem, int len, void *bitstr); |
@@ -122,7 +122,7 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype); | |||
122 | static int asn1_str2tag(const char *tagstr, int len); | 122 | static int asn1_str2tag(const char *tagstr, int len); |
123 | 123 | ||
124 | ASN1_TYPE *ASN1_generate_nconf(char *str, CONF *nconf) | 124 | ASN1_TYPE *ASN1_generate_nconf(char *str, CONF *nconf) |
125 | { | 125 | { |
126 | X509V3_CTX cnf; | 126 | X509V3_CTX cnf; |
127 | 127 | ||
128 | if (!nconf) | 128 | if (!nconf) |
@@ -130,10 +130,10 @@ ASN1_TYPE *ASN1_generate_nconf(char *str, CONF *nconf) | |||
130 | 130 | ||
131 | X509V3_set_nconf(&cnf, nconf); | 131 | X509V3_set_nconf(&cnf, nconf); |
132 | return ASN1_generate_v3(str, &cnf); | 132 | return ASN1_generate_v3(str, &cnf); |
133 | } | 133 | } |
134 | 134 | ||
135 | ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf) | 135 | ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf) |
136 | { | 136 | { |
137 | ASN1_TYPE *ret; | 137 | ASN1_TYPE *ret; |
138 | tag_exp_arg asn1_tags; | 138 | tag_exp_arg asn1_tags; |
139 | tag_exp_type *etmp; | 139 | tag_exp_type *etmp; |
@@ -157,14 +157,14 @@ ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf) | |||
157 | return NULL; | 157 | return NULL; |
158 | 158 | ||
159 | if ((asn1_tags.utype == V_ASN1_SEQUENCE) || (asn1_tags.utype == V_ASN1_SET)) | 159 | if ((asn1_tags.utype == V_ASN1_SEQUENCE) || (asn1_tags.utype == V_ASN1_SET)) |
160 | { | 160 | { |
161 | if (!cnf) | 161 | if (!cnf) |
162 | { | 162 | { |
163 | ASN1err(ASN1_F_ASN1_GENERATE_V3, ASN1_R_SEQUENCE_OR_SET_NEEDS_CONFIG); | 163 | ASN1err(ASN1_F_ASN1_GENERATE_V3, ASN1_R_SEQUENCE_OR_SET_NEEDS_CONFIG); |
164 | return NULL; | 164 | return NULL; |
165 | } | ||
166 | ret = asn1_multi(asn1_tags.utype, asn1_tags.str, cnf); | ||
167 | } | 165 | } |
166 | ret = asn1_multi(asn1_tags.utype, asn1_tags.str, cnf); | ||
167 | } | ||
168 | else | 168 | else |
169 | ret = asn1_str2type(asn1_tags.str, asn1_tags.format, asn1_tags.utype); | 169 | ret = asn1_str2type(asn1_tags.str, asn1_tags.format, asn1_tags.utype); |
170 | 170 | ||
@@ -184,7 +184,7 @@ ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf) | |||
184 | 184 | ||
185 | /* Do we need IMPLICIT tagging? */ | 185 | /* Do we need IMPLICIT tagging? */ |
186 | if (asn1_tags.imp_tag != -1) | 186 | if (asn1_tags.imp_tag != -1) |
187 | { | 187 | { |
188 | /* If IMPLICIT we will replace the underlying tag */ | 188 | /* If IMPLICIT we will replace the underlying tag */ |
189 | /* Skip existing tag+len */ | 189 | /* Skip existing tag+len */ |
190 | r = ASN1_get_object(&cpy_start, &hdr_len, &hdr_tag, &hdr_class, cpy_len); | 190 | r = ASN1_get_object(&cpy_start, &hdr_len, &hdr_tag, &hdr_class, cpy_len); |
@@ -197,11 +197,11 @@ ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf) | |||
197 | * consistent. | 197 | * consistent. |
198 | */ | 198 | */ |
199 | if (r & 0x1) | 199 | if (r & 0x1) |
200 | { | 200 | { |
201 | /* Indefinite length constructed */ | 201 | /* Indefinite length constructed */ |
202 | hdr_constructed = 2; | 202 | hdr_constructed = 2; |
203 | hdr_len = 0; | 203 | hdr_len = 0; |
204 | } | 204 | } |
205 | else | 205 | else |
206 | /* Just retain constructed flag */ | 206 | /* Just retain constructed flag */ |
207 | hdr_constructed = r & V_ASN1_CONSTRUCTED; | 207 | hdr_constructed = r & V_ASN1_CONSTRUCTED; |
@@ -209,20 +209,20 @@ ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf) | |||
209 | * because it will mess up if indefinite length | 209 | * because it will mess up if indefinite length |
210 | */ | 210 | */ |
211 | len = ASN1_object_size(0, hdr_len, asn1_tags.imp_tag); | 211 | len = ASN1_object_size(0, hdr_len, asn1_tags.imp_tag); |
212 | } | 212 | } |
213 | else | 213 | else |
214 | len = cpy_len; | 214 | len = cpy_len; |
215 | 215 | ||
216 | /* Work out length in any EXPLICIT, starting from end */ | 216 | /* Work out length in any EXPLICIT, starting from end */ |
217 | 217 | ||
218 | for(i = 0, etmp = asn1_tags.exp_list + asn1_tags.exp_count - 1; i < asn1_tags.exp_count; i++, etmp--) | 218 | for(i = 0, etmp = asn1_tags.exp_list + asn1_tags.exp_count - 1; i < asn1_tags.exp_count; i++, etmp--) |
219 | { | 219 | { |
220 | /* Content length: number of content octets + any padding */ | 220 | /* Content length: number of content octets + any padding */ |
221 | len += etmp->exp_pad; | 221 | len += etmp->exp_pad; |
222 | etmp->exp_len = len; | 222 | etmp->exp_len = len; |
223 | /* Total object length: length including new header */ | 223 | /* Total object length: length including new header */ |
224 | len = ASN1_object_size(0, len, etmp->exp_tag); | 224 | len = ASN1_object_size(0, len, etmp->exp_tag); |
225 | } | 225 | } |
226 | 226 | ||
227 | /* Allocate buffer for new encoding */ | 227 | /* Allocate buffer for new encoding */ |
228 | 228 | ||
@@ -237,24 +237,24 @@ ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf) | |||
237 | /* Output explicit tags first */ | 237 | /* Output explicit tags first */ |
238 | 238 | ||
239 | for (i = 0, etmp = asn1_tags.exp_list; i < asn1_tags.exp_count; i++, etmp++) | 239 | for (i = 0, etmp = asn1_tags.exp_list; i < asn1_tags.exp_count; i++, etmp++) |
240 | { | 240 | { |
241 | ASN1_put_object(&p, etmp->exp_constructed, etmp->exp_len, | 241 | ASN1_put_object(&p, etmp->exp_constructed, etmp->exp_len, |
242 | etmp->exp_tag, etmp->exp_class); | 242 | etmp->exp_tag, etmp->exp_class); |
243 | if (etmp->exp_pad) | 243 | if (etmp->exp_pad) |
244 | *p++ = 0; | 244 | *p++ = 0; |
245 | } | 245 | } |
246 | 246 | ||
247 | /* If IMPLICIT, output tag */ | 247 | /* If IMPLICIT, output tag */ |
248 | 248 | ||
249 | if (asn1_tags.imp_tag != -1) | 249 | if (asn1_tags.imp_tag != -1) |
250 | { | 250 | { |
251 | if (asn1_tags.imp_class == V_ASN1_UNIVERSAL | 251 | if (asn1_tags.imp_class == V_ASN1_UNIVERSAL |
252 | && (asn1_tags.imp_tag == V_ASN1_SEQUENCE | 252 | && (asn1_tags.imp_tag == V_ASN1_SEQUENCE |
253 | || asn1_tags.imp_tag == V_ASN1_SET) ) | 253 | || asn1_tags.imp_tag == V_ASN1_SET) ) |
254 | hdr_constructed = V_ASN1_CONSTRUCTED; | 254 | hdr_constructed = V_ASN1_CONSTRUCTED; |
255 | ASN1_put_object(&p, hdr_constructed, hdr_len, | 255 | ASN1_put_object(&p, hdr_constructed, hdr_len, |
256 | asn1_tags.imp_tag, asn1_tags.imp_class); | 256 | asn1_tags.imp_tag, asn1_tags.imp_class); |
257 | } | 257 | } |
258 | 258 | ||
259 | /* Copy across original encoding */ | 259 | /* Copy across original encoding */ |
260 | memcpy(p, cpy_start, cpy_len); | 260 | memcpy(p, cpy_start, cpy_len); |
@@ -272,10 +272,10 @@ ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf) | |||
272 | 272 | ||
273 | return ret; | 273 | return ret; |
274 | 274 | ||
275 | } | 275 | } |
276 | 276 | ||
277 | static int asn1_cb(const char *elem, int len, void *bitstr) | 277 | static int asn1_cb(const char *elem, int len, void *bitstr) |
278 | { | 278 | { |
279 | tag_exp_arg *arg = bitstr; | 279 | tag_exp_arg *arg = bitstr; |
280 | int i; | 280 | int i; |
281 | int utype; | 281 | int utype; |
@@ -285,50 +285,50 @@ static int asn1_cb(const char *elem, int len, void *bitstr) | |||
285 | int tmp_tag, tmp_class; | 285 | int tmp_tag, tmp_class; |
286 | 286 | ||
287 | for(i = 0, p = elem; i < len; p++, i++) | 287 | for(i = 0, p = elem; i < len; p++, i++) |
288 | { | 288 | { |
289 | /* Look for the ':' in name value pairs */ | 289 | /* Look for the ':' in name value pairs */ |
290 | if (*p == ':') | 290 | if (*p == ':') |
291 | { | 291 | { |
292 | vstart = p + 1; | 292 | vstart = p + 1; |
293 | vlen = len - (vstart - elem); | 293 | vlen = len - (vstart - elem); |
294 | len = p - elem; | 294 | len = p - elem; |
295 | break; | 295 | break; |
296 | } | ||
297 | } | 296 | } |
297 | } | ||
298 | 298 | ||
299 | utype = asn1_str2tag(elem, len); | 299 | utype = asn1_str2tag(elem, len); |
300 | 300 | ||
301 | if (utype == -1) | 301 | if (utype == -1) |
302 | { | 302 | { |
303 | ASN1err(ASN1_F_ASN1_CB, ASN1_R_UNKNOWN_TAG); | 303 | ASN1err(ASN1_F_ASN1_CB, ASN1_R_UNKNOWN_TAG); |
304 | ERR_add_error_data(2, "tag=", elem); | 304 | ERR_add_error_data(2, "tag=", elem); |
305 | return -1; | 305 | return -1; |
306 | } | 306 | } |
307 | 307 | ||
308 | /* If this is not a modifier mark end of string and exit */ | 308 | /* If this is not a modifier mark end of string and exit */ |
309 | if (!(utype & ASN1_GEN_FLAG)) | 309 | if (!(utype & ASN1_GEN_FLAG)) |
310 | { | 310 | { |
311 | arg->utype = utype; | 311 | arg->utype = utype; |
312 | arg->str = vstart; | 312 | arg->str = vstart; |
313 | /* If no value and not end of string, error */ | 313 | /* If no value and not end of string, error */ |
314 | if (!vstart && elem[len]) | 314 | if (!vstart && elem[len]) |
315 | { | 315 | { |
316 | ASN1err(ASN1_F_ASN1_CB, ASN1_R_MISSING_VALUE); | 316 | ASN1err(ASN1_F_ASN1_CB, ASN1_R_MISSING_VALUE); |
317 | return -1; | 317 | return -1; |
318 | } | ||
319 | return 0; | ||
320 | } | 318 | } |
319 | return 0; | ||
320 | } | ||
321 | 321 | ||
322 | switch(utype) | 322 | switch(utype) |
323 | { | 323 | { |
324 | 324 | ||
325 | case ASN1_GEN_FLAG_IMP: | 325 | case ASN1_GEN_FLAG_IMP: |
326 | /* Check for illegal multiple IMPLICIT tagging */ | 326 | /* Check for illegal multiple IMPLICIT tagging */ |
327 | if (arg->imp_tag != -1) | 327 | if (arg->imp_tag != -1) |
328 | { | 328 | { |
329 | ASN1err(ASN1_F_ASN1_CB, ASN1_R_ILLEGAL_NESTED_TAGGING); | 329 | ASN1err(ASN1_F_ASN1_CB, ASN1_R_ILLEGAL_NESTED_TAGGING); |
330 | return -1; | 330 | return -1; |
331 | } | 331 | } |
332 | if (!parse_tagging(vstart, vlen, &arg->imp_tag, &arg->imp_class)) | 332 | if (!parse_tagging(vstart, vlen, &arg->imp_tag, &arg->imp_class)) |
333 | return -1; | 333 | return -1; |
334 | break; | 334 | break; |
@@ -371,20 +371,20 @@ static int asn1_cb(const char *elem, int len, void *bitstr) | |||
371 | else if (!strncmp(vstart, "BITLIST", 7)) | 371 | else if (!strncmp(vstart, "BITLIST", 7)) |
372 | arg->format = ASN1_GEN_FORMAT_BITLIST; | 372 | arg->format = ASN1_GEN_FORMAT_BITLIST; |
373 | else | 373 | else |
374 | { | 374 | { |
375 | ASN1err(ASN1_F_ASN1_CB, ASN1_R_UNKOWN_FORMAT); | 375 | ASN1err(ASN1_F_ASN1_CB, ASN1_R_UNKOWN_FORMAT); |
376 | return -1; | 376 | return -1; |
377 | } | 377 | } |
378 | break; | 378 | break; |
379 | 379 | ||
380 | } | 380 | } |
381 | 381 | ||
382 | return 1; | 382 | return 1; |
383 | 383 | ||
384 | } | 384 | } |
385 | 385 | ||
386 | static int parse_tagging(const char *vstart, int vlen, int *ptag, int *pclass) | 386 | static int parse_tagging(const char *vstart, int vlen, int *ptag, int *pclass) |
387 | { | 387 | { |
388 | char erch[2]; | 388 | char erch[2]; |
389 | long tag_num; | 389 | long tag_num; |
390 | char *eptr; | 390 | char *eptr; |
@@ -395,10 +395,10 @@ static int parse_tagging(const char *vstart, int vlen, int *ptag, int *pclass) | |||
395 | if (eptr && *eptr && (eptr > vstart + vlen)) | 395 | if (eptr && *eptr && (eptr > vstart + vlen)) |
396 | return 0; | 396 | return 0; |
397 | if (tag_num < 0) | 397 | if (tag_num < 0) |
398 | { | 398 | { |
399 | ASN1err(ASN1_F_PARSE_TAGGING, ASN1_R_INVALID_NUMBER); | 399 | ASN1err(ASN1_F_PARSE_TAGGING, ASN1_R_INVALID_NUMBER); |
400 | return 0; | 400 | return 0; |
401 | } | 401 | } |
402 | *ptag = tag_num; | 402 | *ptag = tag_num; |
403 | /* If we have non numeric characters, parse them */ | 403 | /* If we have non numeric characters, parse them */ |
404 | if (eptr) | 404 | if (eptr) |
@@ -406,9 +406,9 @@ static int parse_tagging(const char *vstart, int vlen, int *ptag, int *pclass) | |||
406 | else | 406 | else |
407 | vlen = 0; | 407 | vlen = 0; |
408 | if (vlen) | 408 | if (vlen) |
409 | { | 409 | { |
410 | switch (*eptr) | 410 | switch (*eptr) |
411 | { | 411 | { |
412 | 412 | ||
413 | case 'U': | 413 | case 'U': |
414 | *pclass = V_ASN1_UNIVERSAL; | 414 | *pclass = V_ASN1_UNIVERSAL; |
@@ -434,19 +434,19 @@ static int parse_tagging(const char *vstart, int vlen, int *ptag, int *pclass) | |||
434 | return 0; | 434 | return 0; |
435 | break; | 435 | break; |
436 | 436 | ||
437 | } | ||
438 | } | 437 | } |
438 | } | ||
439 | else | 439 | else |
440 | *pclass = V_ASN1_CONTEXT_SPECIFIC; | 440 | *pclass = V_ASN1_CONTEXT_SPECIFIC; |
441 | 441 | ||
442 | return 1; | 442 | return 1; |
443 | 443 | ||
444 | } | 444 | } |
445 | 445 | ||
446 | /* Handle multiple types: SET and SEQUENCE */ | 446 | /* Handle multiple types: SET and SEQUENCE */ |
447 | 447 | ||
448 | static ASN1_TYPE *asn1_multi(int utype, const char *section, X509V3_CTX *cnf) | 448 | static ASN1_TYPE *asn1_multi(int utype, const char *section, X509V3_CTX *cnf) |
449 | { | 449 | { |
450 | ASN1_TYPE *ret = NULL; | 450 | ASN1_TYPE *ret = NULL; |
451 | STACK_OF(ASN1_TYPE) *sk = NULL; | 451 | STACK_OF(ASN1_TYPE) *sk = NULL; |
452 | STACK_OF(CONF_VALUE) *sect = NULL; | 452 | STACK_OF(CONF_VALUE) *sect = NULL; |
@@ -457,21 +457,21 @@ static ASN1_TYPE *asn1_multi(int utype, const char *section, X509V3_CTX *cnf) | |||
457 | if (!sk) | 457 | if (!sk) |
458 | goto bad; | 458 | goto bad; |
459 | if (section) | 459 | if (section) |
460 | { | 460 | { |
461 | if (!cnf) | 461 | if (!cnf) |
462 | goto bad; | 462 | goto bad; |
463 | sect = X509V3_get_section(cnf, (char *)section); | 463 | sect = X509V3_get_section(cnf, (char *)section); |
464 | if (!sect) | 464 | if (!sect) |
465 | goto bad; | 465 | goto bad; |
466 | for (i = 0; i < sk_CONF_VALUE_num(sect); i++) | 466 | for (i = 0; i < sk_CONF_VALUE_num(sect); i++) |
467 | { | 467 | { |
468 | ASN1_TYPE *typ = ASN1_generate_v3(sk_CONF_VALUE_value(sect, i)->value, cnf); | 468 | ASN1_TYPE *typ = ASN1_generate_v3(sk_CONF_VALUE_value(sect, i)->value, cnf); |
469 | if (!typ) | 469 | if (!typ) |
470 | goto bad; | 470 | goto bad; |
471 | if (!sk_ASN1_TYPE_push(sk, typ)) | 471 | if (!sk_ASN1_TYPE_push(sk, typ)) |
472 | goto bad; | 472 | goto bad; |
473 | } | ||
474 | } | 473 | } |
474 | } | ||
475 | 475 | ||
476 | /* Now we has a STACK of the components, convert to the correct form */ | 476 | /* Now we has a STACK of the components, convert to the correct form */ |
477 | 477 | ||
@@ -507,23 +507,23 @@ static ASN1_TYPE *asn1_multi(int utype, const char *section, X509V3_CTX *cnf) | |||
507 | X509V3_section_free(cnf, sect); | 507 | X509V3_section_free(cnf, sect); |
508 | 508 | ||
509 | return ret; | 509 | return ret; |
510 | } | 510 | } |
511 | 511 | ||
512 | static int append_exp(tag_exp_arg *arg, int exp_tag, int exp_class, int exp_constructed, int exp_pad, int imp_ok) | 512 | static int append_exp(tag_exp_arg *arg, int exp_tag, int exp_class, int exp_constructed, int exp_pad, int imp_ok) |
513 | { | 513 | { |
514 | tag_exp_type *exp_tmp; | 514 | tag_exp_type *exp_tmp; |
515 | /* Can only have IMPLICIT if permitted */ | 515 | /* Can only have IMPLICIT if permitted */ |
516 | if ((arg->imp_tag != -1) && !imp_ok) | 516 | if ((arg->imp_tag != -1) && !imp_ok) |
517 | { | 517 | { |
518 | ASN1err(ASN1_F_APPEND_EXP, ASN1_R_ILLEGAL_IMPLICIT_TAG); | 518 | ASN1err(ASN1_F_APPEND_EXP, ASN1_R_ILLEGAL_IMPLICIT_TAG); |
519 | return 0; | 519 | return 0; |
520 | } | 520 | } |
521 | 521 | ||
522 | if (arg->exp_count == ASN1_FLAG_EXP_MAX) | 522 | if (arg->exp_count == ASN1_FLAG_EXP_MAX) |
523 | { | 523 | { |
524 | ASN1err(ASN1_F_APPEND_EXP, ASN1_R_DEPTH_EXCEEDED); | 524 | ASN1err(ASN1_F_APPEND_EXP, ASN1_R_DEPTH_EXCEEDED); |
525 | return 0; | 525 | return 0; |
526 | } | 526 | } |
527 | 527 | ||
528 | exp_tmp = &arg->exp_list[arg->exp_count++]; | 528 | exp_tmp = &arg->exp_list[arg->exp_count++]; |
529 | 529 | ||
@@ -531,26 +531,26 @@ static int append_exp(tag_exp_arg *arg, int exp_tag, int exp_class, int exp_cons | |||
531 | * reset implicit tag since it has been used. | 531 | * reset implicit tag since it has been used. |
532 | */ | 532 | */ |
533 | if (arg->imp_tag != -1) | 533 | if (arg->imp_tag != -1) |
534 | { | 534 | { |
535 | exp_tmp->exp_tag = arg->imp_tag; | 535 | exp_tmp->exp_tag = arg->imp_tag; |
536 | exp_tmp->exp_class = arg->imp_class; | 536 | exp_tmp->exp_class = arg->imp_class; |
537 | arg->imp_tag = -1; | 537 | arg->imp_tag = -1; |
538 | arg->imp_class = -1; | 538 | arg->imp_class = -1; |
539 | } | 539 | } |
540 | else | 540 | else |
541 | { | 541 | { |
542 | exp_tmp->exp_tag = exp_tag; | 542 | exp_tmp->exp_tag = exp_tag; |
543 | exp_tmp->exp_class = exp_class; | 543 | exp_tmp->exp_class = exp_class; |
544 | } | 544 | } |
545 | exp_tmp->exp_constructed = exp_constructed; | 545 | exp_tmp->exp_constructed = exp_constructed; |
546 | exp_tmp->exp_pad = exp_pad; | 546 | exp_tmp->exp_pad = exp_pad; |
547 | 547 | ||
548 | return 1; | 548 | return 1; |
549 | } | 549 | } |
550 | 550 | ||
551 | 551 | ||
552 | static int asn1_str2tag(const char *tagstr, int len) | 552 | static int asn1_str2tag(const char *tagstr, int len) |
553 | { | 553 | { |
554 | unsigned int i; | 554 | unsigned int i; |
555 | static const struct tag_name_st *tntmp, tnst [] = { | 555 | static const struct tag_name_st *tntmp, tnst [] = { |
556 | ASN1_GEN_STR("BOOL", V_ASN1_BOOLEAN), | 556 | ASN1_GEN_STR("BOOL", V_ASN1_BOOLEAN), |
@@ -611,23 +611,23 @@ static int asn1_str2tag(const char *tagstr, int len) | |||
611 | ASN1_GEN_STR("BITWRAP", ASN1_GEN_FLAG_BITWRAP), | 611 | ASN1_GEN_STR("BITWRAP", ASN1_GEN_FLAG_BITWRAP), |
612 | ASN1_GEN_STR("FORM", ASN1_GEN_FLAG_FORMAT), | 612 | ASN1_GEN_STR("FORM", ASN1_GEN_FLAG_FORMAT), |
613 | ASN1_GEN_STR("FORMAT", ASN1_GEN_FLAG_FORMAT), | 613 | ASN1_GEN_STR("FORMAT", ASN1_GEN_FLAG_FORMAT), |
614 | }; | 614 | }; |
615 | 615 | ||
616 | if (len == -1) | 616 | if (len == -1) |
617 | len = strlen(tagstr); | 617 | len = strlen(tagstr); |
618 | 618 | ||
619 | tntmp = tnst; | 619 | tntmp = tnst; |
620 | for (i = 0; i < sizeof(tnst) / sizeof(struct tag_name_st); i++, tntmp++) | 620 | for (i = 0; i < sizeof(tnst) / sizeof(struct tag_name_st); i++, tntmp++) |
621 | { | 621 | { |
622 | if ((len == tntmp->len) && !strncmp(tntmp->strnam, tagstr, len)) | 622 | if ((len == tntmp->len) && !strncmp(tntmp->strnam, tagstr, len)) |
623 | return tntmp->tag; | 623 | return tntmp->tag; |
624 | } | 624 | } |
625 | 625 | ||
626 | return -1; | 626 | return -1; |
627 | } | 627 | } |
628 | 628 | ||
629 | static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype) | 629 | static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype) |
630 | { | 630 | { |
631 | ASN1_TYPE *atmp = NULL; | 631 | ASN1_TYPE *atmp = NULL; |
632 | 632 | ||
633 | CONF_VALUE vtmp; | 633 | CONF_VALUE vtmp; |
@@ -638,91 +638,91 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype) | |||
638 | int no_unused = 1; | 638 | int no_unused = 1; |
639 | 639 | ||
640 | if (!(atmp = ASN1_TYPE_new())) | 640 | if (!(atmp = ASN1_TYPE_new())) |
641 | { | 641 | { |
642 | ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE); | 642 | ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE); |
643 | return NULL; | 643 | return NULL; |
644 | } | 644 | } |
645 | 645 | ||
646 | if (!str) | 646 | if (!str) |
647 | str = ""; | 647 | str = ""; |
648 | 648 | ||
649 | switch(utype) | 649 | switch(utype) |
650 | { | 650 | { |
651 | 651 | ||
652 | case V_ASN1_NULL: | 652 | case V_ASN1_NULL: |
653 | if (str && *str) | 653 | if (str && *str) |
654 | { | 654 | { |
655 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_NULL_VALUE); | 655 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_NULL_VALUE); |
656 | goto bad_form; | 656 | goto bad_form; |
657 | } | 657 | } |
658 | break; | 658 | break; |
659 | 659 | ||
660 | case V_ASN1_BOOLEAN: | 660 | case V_ASN1_BOOLEAN: |
661 | if (format != ASN1_GEN_FORMAT_ASCII) | 661 | if (format != ASN1_GEN_FORMAT_ASCII) |
662 | { | 662 | { |
663 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_NOT_ASCII_FORMAT); | 663 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_NOT_ASCII_FORMAT); |
664 | goto bad_form; | 664 | goto bad_form; |
665 | } | 665 | } |
666 | vtmp.name = NULL; | 666 | vtmp.name = NULL; |
667 | vtmp.section = NULL; | 667 | vtmp.section = NULL; |
668 | vtmp.value = (char *)str; | 668 | vtmp.value = (char *)str; |
669 | if (!X509V3_get_value_bool(&vtmp, &atmp->value.boolean)) | 669 | if (!X509V3_get_value_bool(&vtmp, &atmp->value.boolean)) |
670 | { | 670 | { |
671 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_BOOLEAN); | 671 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_BOOLEAN); |
672 | goto bad_str; | 672 | goto bad_str; |
673 | } | 673 | } |
674 | break; | 674 | break; |
675 | 675 | ||
676 | case V_ASN1_INTEGER: | 676 | case V_ASN1_INTEGER: |
677 | case V_ASN1_ENUMERATED: | 677 | case V_ASN1_ENUMERATED: |
678 | if (format != ASN1_GEN_FORMAT_ASCII) | 678 | if (format != ASN1_GEN_FORMAT_ASCII) |
679 | { | 679 | { |
680 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_INTEGER_NOT_ASCII_FORMAT); | 680 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_INTEGER_NOT_ASCII_FORMAT); |
681 | goto bad_form; | 681 | goto bad_form; |
682 | } | 682 | } |
683 | if (!(atmp->value.integer = s2i_ASN1_INTEGER(NULL, (char *)str))) | 683 | if (!(atmp->value.integer = s2i_ASN1_INTEGER(NULL, (char *)str))) |
684 | { | 684 | { |
685 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_INTEGER); | 685 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_INTEGER); |
686 | goto bad_str; | 686 | goto bad_str; |
687 | } | 687 | } |
688 | break; | 688 | break; |
689 | 689 | ||
690 | case V_ASN1_OBJECT: | 690 | case V_ASN1_OBJECT: |
691 | if (format != ASN1_GEN_FORMAT_ASCII) | 691 | if (format != ASN1_GEN_FORMAT_ASCII) |
692 | { | 692 | { |
693 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_OBJECT_NOT_ASCII_FORMAT); | 693 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_OBJECT_NOT_ASCII_FORMAT); |
694 | goto bad_form; | 694 | goto bad_form; |
695 | } | 695 | } |
696 | if (!(atmp->value.object = OBJ_txt2obj(str, 0))) | 696 | if (!(atmp->value.object = OBJ_txt2obj(str, 0))) |
697 | { | 697 | { |
698 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_OBJECT); | 698 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_OBJECT); |
699 | goto bad_str; | 699 | goto bad_str; |
700 | } | 700 | } |
701 | break; | 701 | break; |
702 | 702 | ||
703 | case V_ASN1_UTCTIME: | 703 | case V_ASN1_UTCTIME: |
704 | case V_ASN1_GENERALIZEDTIME: | 704 | case V_ASN1_GENERALIZEDTIME: |
705 | if (format != ASN1_GEN_FORMAT_ASCII) | 705 | if (format != ASN1_GEN_FORMAT_ASCII) |
706 | { | 706 | { |
707 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_TIME_NOT_ASCII_FORMAT); | 707 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_TIME_NOT_ASCII_FORMAT); |
708 | goto bad_form; | 708 | goto bad_form; |
709 | } | 709 | } |
710 | if (!(atmp->value.asn1_string = ASN1_STRING_new())) | 710 | if (!(atmp->value.asn1_string = ASN1_STRING_new())) |
711 | { | 711 | { |
712 | ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE); | 712 | ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE); |
713 | goto bad_str; | 713 | goto bad_str; |
714 | } | 714 | } |
715 | if (!ASN1_STRING_set(atmp->value.asn1_string, str, -1)) | 715 | if (!ASN1_STRING_set(atmp->value.asn1_string, str, -1)) |
716 | { | 716 | { |
717 | ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE); | 717 | ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE); |
718 | goto bad_str; | 718 | goto bad_str; |
719 | } | 719 | } |
720 | atmp->value.asn1_string->type = utype; | 720 | atmp->value.asn1_string->type = utype; |
721 | if (!ASN1_TIME_check(atmp->value.asn1_string)) | 721 | if (!ASN1_TIME_check(atmp->value.asn1_string)) |
722 | { | 722 | { |
723 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_TIME_VALUE); | 723 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_TIME_VALUE); |
724 | goto bad_str; | 724 | goto bad_str; |
725 | } | 725 | } |
726 | 726 | ||
727 | break; | 727 | break; |
728 | 728 | ||
@@ -741,18 +741,18 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype) | |||
741 | else if (format == ASN1_GEN_FORMAT_UTF8) | 741 | else if (format == ASN1_GEN_FORMAT_UTF8) |
742 | format = MBSTRING_UTF8; | 742 | format = MBSTRING_UTF8; |
743 | else | 743 | else |
744 | { | 744 | { |
745 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_FORMAT); | 745 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_FORMAT); |
746 | goto bad_form; | 746 | goto bad_form; |
747 | } | 747 | } |
748 | 748 | ||
749 | 749 | ||
750 | if (ASN1_mbstring_copy(&atmp->value.asn1_string, (unsigned char *)str, | 750 | if (ASN1_mbstring_copy(&atmp->value.asn1_string, (unsigned char *)str, |
751 | -1, format, ASN1_tag2bit(utype)) <= 0) | 751 | -1, format, ASN1_tag2bit(utype)) <= 0) |
752 | { | 752 | { |
753 | ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE); | 753 | ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE); |
754 | goto bad_str; | 754 | goto bad_str; |
755 | } | 755 | } |
756 | 756 | ||
757 | 757 | ||
758 | break; | 758 | break; |
@@ -762,50 +762,50 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype) | |||
762 | case V_ASN1_OCTET_STRING: | 762 | case V_ASN1_OCTET_STRING: |
763 | 763 | ||
764 | if (!(atmp->value.asn1_string = ASN1_STRING_new())) | 764 | if (!(atmp->value.asn1_string = ASN1_STRING_new())) |
765 | { | 765 | { |
766 | ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE); | 766 | ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE); |
767 | goto bad_form; | 767 | goto bad_form; |
768 | } | 768 | } |
769 | 769 | ||
770 | if (format == ASN1_GEN_FORMAT_HEX) | 770 | if (format == ASN1_GEN_FORMAT_HEX) |
771 | { | 771 | { |
772 | 772 | ||
773 | if (!(rdata = string_to_hex((char *)str, &rdlen))) | 773 | if (!(rdata = string_to_hex((char *)str, &rdlen))) |
774 | { | 774 | { |
775 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_HEX); | 775 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_HEX); |
776 | goto bad_str; | 776 | goto bad_str; |
777 | } | 777 | } |
778 | 778 | ||
779 | atmp->value.asn1_string->data = rdata; | 779 | atmp->value.asn1_string->data = rdata; |
780 | atmp->value.asn1_string->length = rdlen; | 780 | atmp->value.asn1_string->length = rdlen; |
781 | atmp->value.asn1_string->type = utype; | 781 | atmp->value.asn1_string->type = utype; |
782 | 782 | ||
783 | } | 783 | } |
784 | else if (format == ASN1_GEN_FORMAT_ASCII) | 784 | else if (format == ASN1_GEN_FORMAT_ASCII) |
785 | ASN1_STRING_set(atmp->value.asn1_string, str, -1); | 785 | ASN1_STRING_set(atmp->value.asn1_string, str, -1); |
786 | else if ((format == ASN1_GEN_FORMAT_BITLIST) && (utype == V_ASN1_BIT_STRING)) | 786 | else if ((format == ASN1_GEN_FORMAT_BITLIST) && (utype == V_ASN1_BIT_STRING)) |
787 | { | 787 | { |
788 | if (!CONF_parse_list(str, ',', 1, bitstr_cb, atmp->value.bit_string)) | 788 | if (!CONF_parse_list(str, ',', 1, bitstr_cb, atmp->value.bit_string)) |
789 | { | 789 | { |
790 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_LIST_ERROR); | 790 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_LIST_ERROR); |
791 | goto bad_str; | 791 | goto bad_str; |
792 | } | 792 | } |
793 | no_unused = 0; | 793 | no_unused = 0; |
794 | 794 | ||
795 | } | 795 | } |
796 | else | 796 | else |
797 | { | 797 | { |
798 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_BITSTRING_FORMAT); | 798 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_BITSTRING_FORMAT); |
799 | goto bad_form; | 799 | goto bad_form; |
800 | } | 800 | } |
801 | 801 | ||
802 | if ((utype == V_ASN1_BIT_STRING) && no_unused) | 802 | if ((utype == V_ASN1_BIT_STRING) && no_unused) |
803 | { | 803 | { |
804 | atmp->value.asn1_string->flags | 804 | atmp->value.asn1_string->flags |
805 | &= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); | 805 | &= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); |
806 | atmp->value.asn1_string->flags | 806 | atmp->value.asn1_string->flags |
807 | |= ASN1_STRING_FLAG_BITS_LEFT; | 807 | |= ASN1_STRING_FLAG_BITS_LEFT; |
808 | } | 808 | } |
809 | 809 | ||
810 | 810 | ||
811 | break; | 811 | break; |
@@ -814,7 +814,7 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype) | |||
814 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_UNSUPPORTED_TYPE); | 814 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_UNSUPPORTED_TYPE); |
815 | goto bad_str; | 815 | goto bad_str; |
816 | break; | 816 | break; |
817 | } | 817 | } |
818 | 818 | ||
819 | 819 | ||
820 | atmp->type = utype; | 820 | atmp->type = utype; |
@@ -828,10 +828,10 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype) | |||
828 | ASN1_TYPE_free(atmp); | 828 | ASN1_TYPE_free(atmp); |
829 | return NULL; | 829 | return NULL; |
830 | 830 | ||
831 | } | 831 | } |
832 | 832 | ||
833 | static int bitstr_cb(const char *elem, int len, void *bitstr) | 833 | static int bitstr_cb(const char *elem, int len, void *bitstr) |
834 | { | 834 | { |
835 | long bitnum; | 835 | long bitnum; |
836 | char *eptr; | 836 | char *eptr; |
837 | if (!elem) | 837 | if (!elem) |
@@ -840,15 +840,15 @@ static int bitstr_cb(const char *elem, int len, void *bitstr) | |||
840 | if (eptr && *eptr && (eptr != elem + len)) | 840 | if (eptr && *eptr && (eptr != elem + len)) |
841 | return 0; | 841 | return 0; |
842 | if (bitnum < 0) | 842 | if (bitnum < 0) |
843 | { | 843 | { |
844 | ASN1err(ASN1_F_BITSTR_CB, ASN1_R_INVALID_NUMBER); | 844 | ASN1err(ASN1_F_BITSTR_CB, ASN1_R_INVALID_NUMBER); |
845 | return 0; | 845 | return 0; |
846 | } | 846 | } |
847 | if (!ASN1_BIT_STRING_set_bit(bitstr, bitnum, 1)) | 847 | if (!ASN1_BIT_STRING_set_bit(bitstr, bitnum, 1)) |
848 | { | 848 | { |
849 | ASN1err(ASN1_F_BITSTR_CB, ERR_R_MALLOC_FAILURE); | 849 | ASN1err(ASN1_F_BITSTR_CB, ERR_R_MALLOC_FAILURE); |
850 | return 0; | 850 | return 0; |
851 | } | ||
852 | return 1; | ||
853 | } | 851 | } |
852 | return 1; | ||
853 | } | ||
854 | 854 | ||
diff --git a/src/lib/libcrypto/asn1/asn1_lib.c b/src/lib/libcrypto/asn1/asn1_lib.c index 7b06b6fdc8..6ec383859f 100644 --- a/src/lib/libcrypto/asn1/asn1_lib.c +++ b/src/lib/libcrypto/asn1/asn1_lib.c | |||
@@ -67,33 +67,33 @@ static void asn1_put_length(unsigned char **pp, int length); | |||
67 | const char ASN1_version[]="ASN.1" OPENSSL_VERSION_PTEXT; | 67 | const char ASN1_version[]="ASN.1" OPENSSL_VERSION_PTEXT; |
68 | 68 | ||
69 | static int _asn1_check_infinite_end(const unsigned char **p, long len) | 69 | static int _asn1_check_infinite_end(const unsigned char **p, long len) |
70 | { | 70 | { |
71 | /* If there is 0 or 1 byte left, the length check should pick | 71 | /* If there is 0 or 1 byte left, the length check should pick |
72 | * things up */ | 72 | * things up */ |
73 | if (len <= 0) | 73 | if (len <= 0) |
74 | return(1); | 74 | return(1); |
75 | else if ((len >= 2) && ((*p)[0] == 0) && ((*p)[1] == 0)) | 75 | else if ((len >= 2) && ((*p)[0] == 0) && ((*p)[1] == 0)) |
76 | { | 76 | { |
77 | (*p)+=2; | 77 | (*p)+=2; |
78 | return(1); | 78 | return(1); |
79 | } | ||
80 | return(0); | ||
81 | } | 79 | } |
80 | return(0); | ||
81 | } | ||
82 | 82 | ||
83 | int ASN1_check_infinite_end(unsigned char **p, long len) | 83 | int ASN1_check_infinite_end(unsigned char **p, long len) |
84 | { | 84 | { |
85 | return _asn1_check_infinite_end((const unsigned char **)p, len); | 85 | return _asn1_check_infinite_end((const unsigned char **)p, len); |
86 | } | 86 | } |
87 | 87 | ||
88 | int ASN1_const_check_infinite_end(const unsigned char **p, long len) | 88 | int ASN1_const_check_infinite_end(const unsigned char **p, long len) |
89 | { | 89 | { |
90 | return _asn1_check_infinite_end(p, len); | 90 | return _asn1_check_infinite_end(p, len); |
91 | } | 91 | } |
92 | 92 | ||
93 | 93 | ||
94 | int ASN1_get_object(const unsigned char **pp, long *plength, int *ptag, | 94 | int ASN1_get_object(const unsigned char **pp, long *plength, int *ptag, |
95 | int *pclass, long omax) | 95 | int *pclass, long omax) |
96 | { | 96 | { |
97 | int i,ret; | 97 | int i,ret; |
98 | long l; | 98 | long l; |
99 | const unsigned char *p= *pp; | 99 | const unsigned char *p= *pp; |
@@ -105,28 +105,28 @@ int ASN1_get_object(const unsigned char **pp, long *plength, int *ptag, | |||
105 | xclass=(*p&V_ASN1_PRIVATE); | 105 | xclass=(*p&V_ASN1_PRIVATE); |
106 | i= *p&V_ASN1_PRIMITIVE_TAG; | 106 | i= *p&V_ASN1_PRIMITIVE_TAG; |
107 | if (i == V_ASN1_PRIMITIVE_TAG) | 107 | if (i == V_ASN1_PRIMITIVE_TAG) |
108 | { /* high-tag */ | 108 | { /* high-tag */ |
109 | p++; | 109 | p++; |
110 | if (--max == 0) goto err; | 110 | if (--max == 0) goto err; |
111 | l=0; | 111 | l=0; |
112 | while (*p&0x80) | 112 | while (*p&0x80) |
113 | { | 113 | { |
114 | l<<=7L; | 114 | l<<=7L; |
115 | l|= *(p++)&0x7f; | 115 | l|= *(p++)&0x7f; |
116 | if (--max == 0) goto err; | 116 | if (--max == 0) goto err; |
117 | if (l > (INT_MAX >> 7L)) goto err; | 117 | if (l > (INT_MAX >> 7L)) goto err; |
118 | } | 118 | } |
119 | l<<=7L; | 119 | l<<=7L; |
120 | l|= *(p++)&0x7f; | 120 | l|= *(p++)&0x7f; |
121 | tag=(int)l; | 121 | tag=(int)l; |
122 | if (--max == 0) goto err; | 122 | if (--max == 0) goto err; |
123 | } | 123 | } |
124 | else | 124 | else |
125 | { | 125 | { |
126 | tag=i; | 126 | tag=i; |
127 | p++; | 127 | p++; |
128 | if (--max == 0) goto err; | 128 | if (--max == 0) goto err; |
129 | } | 129 | } |
130 | *ptag=tag; | 130 | *ptag=tag; |
131 | *pclass=xclass; | 131 | *pclass=xclass; |
132 | if (!asn1_get_length(&p,&inf,plength,(int)max)) goto err; | 132 | if (!asn1_get_length(&p,&inf,plength,(int)max)) goto err; |
@@ -138,63 +138,63 @@ int ASN1_get_object(const unsigned char **pp, long *plength, int *ptag, | |||
138 | 138 | ||
139 | #endif | 139 | #endif |
140 | if (*plength > (omax - (p - *pp))) | 140 | if (*plength > (omax - (p - *pp))) |
141 | { | 141 | { |
142 | ASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_TOO_LONG); | 142 | ASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_TOO_LONG); |
143 | /* Set this so that even if things are not long enough | 143 | /* Set this so that even if things are not long enough |
144 | * the values are set correctly */ | 144 | * the values are set correctly */ |
145 | ret|=0x80; | 145 | ret|=0x80; |
146 | } | 146 | } |
147 | *pp=p; | 147 | *pp=p; |
148 | return(ret|inf); | 148 | return(ret|inf); |
149 | err: | 149 | err: |
150 | ASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_HEADER_TOO_LONG); | 150 | ASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_HEADER_TOO_LONG); |
151 | return(0x80); | 151 | return(0x80); |
152 | } | 152 | } |
153 | 153 | ||
154 | static int asn1_get_length(const unsigned char **pp, int *inf, long *rl, int max) | 154 | static int asn1_get_length(const unsigned char **pp, int *inf, long *rl, int max) |
155 | { | 155 | { |
156 | const unsigned char *p= *pp; | 156 | const unsigned char *p= *pp; |
157 | unsigned long ret=0; | 157 | unsigned long ret=0; |
158 | unsigned int i; | 158 | unsigned int i; |
159 | 159 | ||
160 | if (max-- < 1) return(0); | 160 | if (max-- < 1) return(0); |
161 | if (*p == 0x80) | 161 | if (*p == 0x80) |
162 | { | 162 | { |
163 | *inf=1; | 163 | *inf=1; |
164 | ret=0; | 164 | ret=0; |
165 | p++; | 165 | p++; |
166 | } | 166 | } |
167 | else | 167 | else |
168 | { | 168 | { |
169 | *inf=0; | 169 | *inf=0; |
170 | i= *p&0x7f; | 170 | i= *p&0x7f; |
171 | if (*(p++) & 0x80) | 171 | if (*(p++) & 0x80) |
172 | { | 172 | { |
173 | if (i > sizeof(long)) | 173 | if (i > sizeof(long)) |
174 | return 0; | 174 | return 0; |
175 | if (max-- == 0) return(0); | 175 | if (max-- == 0) return(0); |
176 | while (i-- > 0) | 176 | while (i-- > 0) |
177 | { | 177 | { |
178 | ret<<=8L; | 178 | ret<<=8L; |
179 | ret|= *(p++); | 179 | ret|= *(p++); |
180 | if (max-- == 0) return(0); | 180 | if (max-- == 0) return(0); |
181 | } | ||
182 | } | 181 | } |
182 | } | ||
183 | else | 183 | else |
184 | ret=i; | 184 | ret=i; |
185 | } | 185 | } |
186 | if (ret > LONG_MAX) | 186 | if (ret > LONG_MAX) |
187 | return 0; | 187 | return 0; |
188 | *pp=p; | 188 | *pp=p; |
189 | *rl=(long)ret; | 189 | *rl=(long)ret; |
190 | return(1); | 190 | return(1); |
191 | } | 191 | } |
192 | 192 | ||
193 | /* class 0 is constructed | 193 | /* class 0 is constructed |
194 | * constructed == 2 for indefinite length constructed */ | 194 | * constructed == 2 for indefinite length constructed */ |
195 | void ASN1_put_object(unsigned char **pp, int constructed, int length, int tag, | 195 | void ASN1_put_object(unsigned char **pp, int constructed, int length, int tag, |
196 | int xclass) | 196 | int xclass) |
197 | { | 197 | { |
198 | unsigned char *p= *pp; | 198 | unsigned char *p= *pp; |
199 | int i, ttag; | 199 | int i, ttag; |
200 | 200 | ||
@@ -203,145 +203,145 @@ void ASN1_put_object(unsigned char **pp, int constructed, int length, int tag, | |||
203 | if (tag < 31) | 203 | if (tag < 31) |
204 | *(p++)=i|(tag&V_ASN1_PRIMITIVE_TAG); | 204 | *(p++)=i|(tag&V_ASN1_PRIMITIVE_TAG); |
205 | else | 205 | else |
206 | { | 206 | { |
207 | *(p++)=i|V_ASN1_PRIMITIVE_TAG; | 207 | *(p++)=i|V_ASN1_PRIMITIVE_TAG; |
208 | for(i = 0, ttag = tag; ttag > 0; i++) ttag >>=7; | 208 | for(i = 0, ttag = tag; ttag > 0; i++) ttag >>=7; |
209 | ttag = i; | 209 | ttag = i; |
210 | while(i-- > 0) | 210 | while(i-- > 0) |
211 | { | 211 | { |
212 | p[i] = tag & 0x7f; | 212 | p[i] = tag & 0x7f; |
213 | if(i != (ttag - 1)) p[i] |= 0x80; | 213 | if(i != (ttag - 1)) p[i] |= 0x80; |
214 | tag >>= 7; | 214 | tag >>= 7; |
215 | } | ||
216 | p += ttag; | ||
217 | } | 215 | } |
216 | p += ttag; | ||
217 | } | ||
218 | if (constructed == 2) | 218 | if (constructed == 2) |
219 | *(p++)=0x80; | 219 | *(p++)=0x80; |
220 | else | 220 | else |
221 | asn1_put_length(&p,length); | 221 | asn1_put_length(&p,length); |
222 | *pp=p; | 222 | *pp=p; |
223 | } | 223 | } |
224 | 224 | ||
225 | int ASN1_put_eoc(unsigned char **pp) | 225 | int ASN1_put_eoc(unsigned char **pp) |
226 | { | 226 | { |
227 | unsigned char *p = *pp; | 227 | unsigned char *p = *pp; |
228 | *p++ = 0; | 228 | *p++ = 0; |
229 | *p++ = 0; | 229 | *p++ = 0; |
230 | *pp = p; | 230 | *pp = p; |
231 | return 2; | 231 | return 2; |
232 | } | 232 | } |
233 | 233 | ||
234 | static void asn1_put_length(unsigned char **pp, int length) | 234 | static void asn1_put_length(unsigned char **pp, int length) |
235 | { | 235 | { |
236 | unsigned char *p= *pp; | 236 | unsigned char *p= *pp; |
237 | int i,l; | 237 | int i,l; |
238 | if (length <= 127) | 238 | if (length <= 127) |
239 | *(p++)=(unsigned char)length; | 239 | *(p++)=(unsigned char)length; |
240 | else | 240 | else |
241 | { | 241 | { |
242 | l=length; | 242 | l=length; |
243 | for (i=0; l > 0; i++) | 243 | for (i=0; l > 0; i++) |
244 | l>>=8; | 244 | l>>=8; |
245 | *(p++)=i|0x80; | 245 | *(p++)=i|0x80; |
246 | l=i; | 246 | l=i; |
247 | while (i-- > 0) | 247 | while (i-- > 0) |
248 | { | 248 | { |
249 | p[i]=length&0xff; | 249 | p[i]=length&0xff; |
250 | length>>=8; | 250 | length>>=8; |
251 | } | ||
252 | p+=l; | ||
253 | } | 251 | } |
254 | *pp=p; | 252 | p+=l; |
255 | } | 253 | } |
254 | *pp=p; | ||
255 | } | ||
256 | 256 | ||
257 | int ASN1_object_size(int constructed, int length, int tag) | 257 | int ASN1_object_size(int constructed, int length, int tag) |
258 | { | 258 | { |
259 | int ret; | 259 | int ret; |
260 | 260 | ||
261 | ret=length; | 261 | ret=length; |
262 | ret++; | 262 | ret++; |
263 | if (tag >= 31) | 263 | if (tag >= 31) |
264 | { | 264 | { |
265 | while (tag > 0) | 265 | while (tag > 0) |
266 | { | 266 | { |
267 | tag>>=7; | 267 | tag>>=7; |
268 | ret++; | 268 | ret++; |
269 | } | ||
270 | } | 269 | } |
270 | } | ||
271 | if (constructed == 2) | 271 | if (constructed == 2) |
272 | return ret + 3; | 272 | return ret + 3; |
273 | ret++; | 273 | ret++; |
274 | if (length > 127) | 274 | if (length > 127) |
275 | { | 275 | { |
276 | while (length > 0) | 276 | while (length > 0) |
277 | { | 277 | { |
278 | length>>=8; | 278 | length>>=8; |
279 | ret++; | 279 | ret++; |
280 | } | ||
281 | } | 280 | } |
282 | return(ret); | ||
283 | } | 281 | } |
282 | return(ret); | ||
283 | } | ||
284 | 284 | ||
285 | static int _asn1_Finish(ASN1_const_CTX *c) | 285 | static int _asn1_Finish(ASN1_const_CTX *c) |
286 | { | 286 | { |
287 | if ((c->inf == (1|V_ASN1_CONSTRUCTED)) && (!c->eos)) | 287 | if ((c->inf == (1|V_ASN1_CONSTRUCTED)) && (!c->eos)) |
288 | { | 288 | { |
289 | if (!ASN1_const_check_infinite_end(&c->p,c->slen)) | 289 | if (!ASN1_const_check_infinite_end(&c->p,c->slen)) |
290 | { | 290 | { |
291 | c->error=ERR_R_MISSING_ASN1_EOS; | 291 | c->error=ERR_R_MISSING_ASN1_EOS; |
292 | return(0); | 292 | return(0); |
293 | } | ||
294 | } | 293 | } |
294 | } | ||
295 | if ( ((c->slen != 0) && !(c->inf & 1)) || | 295 | if ( ((c->slen != 0) && !(c->inf & 1)) || |
296 | ((c->slen < 0) && (c->inf & 1))) | 296 | ((c->slen < 0) && (c->inf & 1))) |
297 | { | 297 | { |
298 | c->error=ERR_R_ASN1_LENGTH_MISMATCH; | 298 | c->error=ERR_R_ASN1_LENGTH_MISMATCH; |
299 | return(0); | 299 | return(0); |
300 | } | ||
301 | return(1); | ||
302 | } | 300 | } |
301 | return(1); | ||
302 | } | ||
303 | 303 | ||
304 | int asn1_Finish(ASN1_CTX *c) | 304 | int asn1_Finish(ASN1_CTX *c) |
305 | { | 305 | { |
306 | return _asn1_Finish((ASN1_const_CTX *)c); | 306 | return _asn1_Finish((ASN1_const_CTX *)c); |
307 | } | 307 | } |
308 | 308 | ||
309 | int asn1_const_Finish(ASN1_const_CTX *c) | 309 | int asn1_const_Finish(ASN1_const_CTX *c) |
310 | { | 310 | { |
311 | return _asn1_Finish(c); | 311 | return _asn1_Finish(c); |
312 | } | 312 | } |
313 | 313 | ||
314 | int asn1_GetSequence(ASN1_const_CTX *c, long *length) | 314 | int asn1_GetSequence(ASN1_const_CTX *c, long *length) |
315 | { | 315 | { |
316 | const unsigned char *q; | 316 | const unsigned char *q; |
317 | 317 | ||
318 | q=c->p; | 318 | q=c->p; |
319 | c->inf=ASN1_get_object(&(c->p),&(c->slen),&(c->tag),&(c->xclass), | 319 | c->inf=ASN1_get_object(&(c->p),&(c->slen),&(c->tag),&(c->xclass), |
320 | *length); | 320 | *length); |
321 | if (c->inf & 0x80) | 321 | if (c->inf & 0x80) |
322 | { | 322 | { |
323 | c->error=ERR_R_BAD_GET_ASN1_OBJECT_CALL; | 323 | c->error=ERR_R_BAD_GET_ASN1_OBJECT_CALL; |
324 | return(0); | 324 | return(0); |
325 | } | 325 | } |
326 | if (c->tag != V_ASN1_SEQUENCE) | 326 | if (c->tag != V_ASN1_SEQUENCE) |
327 | { | 327 | { |
328 | c->error=ERR_R_EXPECTING_AN_ASN1_SEQUENCE; | 328 | c->error=ERR_R_EXPECTING_AN_ASN1_SEQUENCE; |
329 | return(0); | 329 | return(0); |
330 | } | 330 | } |
331 | (*length)-=(c->p-q); | 331 | (*length)-=(c->p-q); |
332 | if (c->max && (*length < 0)) | 332 | if (c->max && (*length < 0)) |
333 | { | 333 | { |
334 | c->error=ERR_R_ASN1_LENGTH_MISMATCH; | 334 | c->error=ERR_R_ASN1_LENGTH_MISMATCH; |
335 | return(0); | 335 | return(0); |
336 | } | 336 | } |
337 | if (c->inf == (1|V_ASN1_CONSTRUCTED)) | 337 | if (c->inf == (1|V_ASN1_CONSTRUCTED)) |
338 | c->slen= *length+ *(c->pp)-c->p; | 338 | c->slen= *length+ *(c->pp)-c->p; |
339 | c->eos=0; | 339 | c->eos=0; |
340 | return(1); | 340 | return(1); |
341 | } | 341 | } |
342 | 342 | ||
343 | int ASN1_STRING_copy(ASN1_STRING *dst, const ASN1_STRING *str) | 343 | int ASN1_STRING_copy(ASN1_STRING *dst, const ASN1_STRING *str) |
344 | { | 344 | { |
345 | if (str == NULL) | 345 | if (str == NULL) |
346 | return 0; | 346 | return 0; |
347 | dst->type = str->type; | 347 | dst->type = str->type; |
@@ -349,10 +349,10 @@ int ASN1_STRING_copy(ASN1_STRING *dst, const ASN1_STRING *str) | |||
349 | return 0; | 349 | return 0; |
350 | dst->flags = str->flags; | 350 | dst->flags = str->flags; |
351 | return 1; | 351 | return 1; |
352 | } | 352 | } |
353 | 353 | ||
354 | ASN1_STRING *ASN1_STRING_dup(const ASN1_STRING *str) | 354 | ASN1_STRING *ASN1_STRING_dup(const ASN1_STRING *str) |
355 | { | 355 | { |
356 | ASN1_STRING *ret; | 356 | ASN1_STRING *ret; |
357 | if (!str) | 357 | if (!str) |
358 | return NULL; | 358 | return NULL; |
@@ -360,27 +360,27 @@ ASN1_STRING *ASN1_STRING_dup(const ASN1_STRING *str) | |||
360 | if (!ret) | 360 | if (!ret) |
361 | return NULL; | 361 | return NULL; |
362 | if (!ASN1_STRING_copy(ret,str)) | 362 | if (!ASN1_STRING_copy(ret,str)) |
363 | { | 363 | { |
364 | ASN1_STRING_free(ret); | 364 | ASN1_STRING_free(ret); |
365 | return NULL; | 365 | return NULL; |
366 | } | ||
367 | return ret; | ||
368 | } | 366 | } |
367 | return ret; | ||
368 | } | ||
369 | 369 | ||
370 | int ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len) | 370 | int ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len) |
371 | { | 371 | { |
372 | unsigned char *c; | 372 | unsigned char *c; |
373 | const char *data=_data; | 373 | const char *data=_data; |
374 | 374 | ||
375 | if (len < 0) | 375 | if (len < 0) |
376 | { | 376 | { |
377 | if (data == NULL) | 377 | if (data == NULL) |
378 | return(0); | 378 | return(0); |
379 | else | 379 | else |
380 | len=strlen(data); | 380 | len=strlen(data); |
381 | } | 381 | } |
382 | if ((str->length < len) || (str->data == NULL)) | 382 | if ((str->length < len) || (str->data == NULL)) |
383 | { | 383 | { |
384 | c=str->data; | 384 | c=str->data; |
385 | if (c == NULL) | 385 | if (c == NULL) |
386 | str->data=malloc(len+1); | 386 | str->data=malloc(len+1); |
@@ -388,86 +388,86 @@ int ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len) | |||
388 | str->data=realloc(c,len+1); | 388 | str->data=realloc(c,len+1); |
389 | 389 | ||
390 | if (str->data == NULL) | 390 | if (str->data == NULL) |
391 | { | 391 | { |
392 | ASN1err(ASN1_F_ASN1_STRING_SET,ERR_R_MALLOC_FAILURE); | 392 | ASN1err(ASN1_F_ASN1_STRING_SET,ERR_R_MALLOC_FAILURE); |
393 | str->data=c; | 393 | str->data=c; |
394 | return(0); | 394 | return(0); |
395 | } | ||
396 | } | 395 | } |
396 | } | ||
397 | str->length=len; | 397 | str->length=len; |
398 | if (data != NULL) | 398 | if (data != NULL) |
399 | { | 399 | { |
400 | memcpy(str->data,data,len); | 400 | memcpy(str->data,data,len); |
401 | /* an allowance for strings :-) */ | 401 | /* an allowance for strings :-) */ |
402 | str->data[len]='\0'; | 402 | str->data[len]='\0'; |
403 | } | ||
404 | return(1); | ||
405 | } | 403 | } |
404 | return(1); | ||
405 | } | ||
406 | 406 | ||
407 | void ASN1_STRING_set0(ASN1_STRING *str, void *data, int len) | 407 | void ASN1_STRING_set0(ASN1_STRING *str, void *data, int len) |
408 | { | 408 | { |
409 | if (str->data) | 409 | if (str->data) |
410 | free(str->data); | 410 | free(str->data); |
411 | str->data = data; | 411 | str->data = data; |
412 | str->length = len; | 412 | str->length = len; |
413 | } | 413 | } |
414 | 414 | ||
415 | ASN1_STRING *ASN1_STRING_new(void) | 415 | ASN1_STRING *ASN1_STRING_new(void) |
416 | { | 416 | { |
417 | return(ASN1_STRING_type_new(V_ASN1_OCTET_STRING)); | 417 | return(ASN1_STRING_type_new(V_ASN1_OCTET_STRING)); |
418 | } | 418 | } |
419 | 419 | ||
420 | 420 | ||
421 | ASN1_STRING *ASN1_STRING_type_new(int type) | 421 | ASN1_STRING *ASN1_STRING_type_new(int type) |
422 | { | 422 | { |
423 | ASN1_STRING *ret; | 423 | ASN1_STRING *ret; |
424 | 424 | ||
425 | ret=(ASN1_STRING *)malloc(sizeof(ASN1_STRING)); | 425 | ret=(ASN1_STRING *)malloc(sizeof(ASN1_STRING)); |
426 | if (ret == NULL) | 426 | if (ret == NULL) |
427 | { | 427 | { |
428 | ASN1err(ASN1_F_ASN1_STRING_TYPE_NEW,ERR_R_MALLOC_FAILURE); | 428 | ASN1err(ASN1_F_ASN1_STRING_TYPE_NEW,ERR_R_MALLOC_FAILURE); |
429 | return(NULL); | 429 | return(NULL); |
430 | } | 430 | } |
431 | ret->length=0; | 431 | ret->length=0; |
432 | ret->type=type; | 432 | ret->type=type; |
433 | ret->data=NULL; | 433 | ret->data=NULL; |
434 | ret->flags=0; | 434 | ret->flags=0; |
435 | return(ret); | 435 | return(ret); |
436 | } | 436 | } |
437 | 437 | ||
438 | void ASN1_STRING_free(ASN1_STRING *a) | 438 | void ASN1_STRING_free(ASN1_STRING *a) |
439 | { | 439 | { |
440 | if (a == NULL) return; | 440 | if (a == NULL) return; |
441 | if (a->data && !(a->flags & ASN1_STRING_FLAG_NDEF)) | 441 | if (a->data && !(a->flags & ASN1_STRING_FLAG_NDEF)) |
442 | free(a->data); | 442 | free(a->data); |
443 | free(a); | 443 | free(a); |
444 | } | 444 | } |
445 | 445 | ||
446 | int ASN1_STRING_cmp(const ASN1_STRING *a, const ASN1_STRING *b) | 446 | int ASN1_STRING_cmp(const ASN1_STRING *a, const ASN1_STRING *b) |
447 | { | 447 | { |
448 | int i; | 448 | int i; |
449 | 449 | ||
450 | i=(a->length-b->length); | 450 | i=(a->length-b->length); |
451 | if (i == 0) | 451 | if (i == 0) |
452 | { | 452 | { |
453 | i=memcmp(a->data,b->data,a->length); | 453 | i=memcmp(a->data,b->data,a->length); |
454 | if (i == 0) | 454 | if (i == 0) |
455 | return(a->type-b->type); | 455 | return(a->type-b->type); |
456 | else | 456 | else |
457 | return(i); | 457 | return(i); |
458 | } | 458 | } |
459 | else | 459 | else |
460 | return(i); | 460 | return(i); |
461 | } | 461 | } |
462 | 462 | ||
463 | void asn1_add_error(const unsigned char *address, int offset) | 463 | void asn1_add_error(const unsigned char *address, int offset) |
464 | { | 464 | { |
465 | char buf1[DECIMAL_SIZE(address)+1],buf2[DECIMAL_SIZE(offset)+1]; | 465 | char buf1[DECIMAL_SIZE(address)+1],buf2[DECIMAL_SIZE(offset)+1]; |
466 | 466 | ||
467 | (void) snprintf(buf1,sizeof buf1,"%lu",(unsigned long)address); | 467 | (void) snprintf(buf1,sizeof buf1,"%lu",(unsigned long)address); |
468 | (void) snprintf(buf2,sizeof buf2,"%d",offset); | 468 | (void) snprintf(buf2,sizeof buf2,"%d",offset); |
469 | ERR_add_error_data(4,"address=",buf1," offset=",buf2); | 469 | ERR_add_error_data(4,"address=",buf1," offset=",buf2); |
470 | } | 470 | } |
471 | 471 | ||
472 | int ASN1_STRING_length(const ASN1_STRING *x) | 472 | int ASN1_STRING_length(const ASN1_STRING *x) |
473 | { return M_ASN1_STRING_length(x); } | 473 | { return M_ASN1_STRING_length(x); } |
diff --git a/src/lib/libcrypto/asn1/asn1_par.c b/src/lib/libcrypto/asn1/asn1_par.c index e34c75a418..d68d4a8298 100644 --- a/src/lib/libcrypto/asn1/asn1_par.c +++ b/src/lib/libcrypto/asn1/asn1_par.c | |||
@@ -68,7 +68,7 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, | |||
68 | int offset, int depth, int indent, int dump); | 68 | int offset, int depth, int indent, int dump); |
69 | static int asn1_print_info(BIO *bp, int tag, int xclass, int constructed, | 69 | static int asn1_print_info(BIO *bp, int tag, int xclass, int constructed, |
70 | int indent) | 70 | int indent) |
71 | { | 71 | { |
72 | static const char fmt[]="%-18s"; | 72 | static const char fmt[]="%-18s"; |
73 | char str[128]; | 73 | char str[128]; |
74 | const char *p; | 74 | const char *p; |
@@ -97,21 +97,21 @@ static int asn1_print_info(BIO *bp, int tag, int xclass, int constructed, | |||
97 | return(1); | 97 | return(1); |
98 | err: | 98 | err: |
99 | return(0); | 99 | return(0); |
100 | } | 100 | } |
101 | 101 | ||
102 | int ASN1_parse(BIO *bp, const unsigned char *pp, long len, int indent) | 102 | int ASN1_parse(BIO *bp, const unsigned char *pp, long len, int indent) |
103 | { | 103 | { |
104 | return(asn1_parse2(bp,&pp,len,0,0,indent,0)); | 104 | return(asn1_parse2(bp,&pp,len,0,0,indent,0)); |
105 | } | 105 | } |
106 | 106 | ||
107 | int ASN1_parse_dump(BIO *bp, const unsigned char *pp, long len, int indent, int dump) | 107 | int ASN1_parse_dump(BIO *bp, const unsigned char *pp, long len, int indent, int dump) |
108 | { | 108 | { |
109 | return(asn1_parse2(bp,&pp,len,0,0,indent,dump)); | 109 | return(asn1_parse2(bp,&pp,len,0,0,indent,dump)); |
110 | } | 110 | } |
111 | 111 | ||
112 | static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offset, | 112 | static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offset, |
113 | int depth, int indent, int dump) | 113 | int depth, int indent, int dump) |
114 | { | 114 | { |
115 | const unsigned char *p,*ep,*tot,*op,*opp; | 115 | const unsigned char *p,*ep,*tot,*op,*opp; |
116 | long len; | 116 | long len; |
117 | int tag,xclass,ret=0; | 117 | int tag,xclass,ret=0; |
@@ -130,19 +130,19 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offse | |||
130 | tot=p+length; | 130 | tot=p+length; |
131 | op=p-1; | 131 | op=p-1; |
132 | while ((p < tot) && (op < p)) | 132 | while ((p < tot) && (op < p)) |
133 | { | 133 | { |
134 | op=p; | 134 | op=p; |
135 | j=ASN1_get_object(&p,&len,&tag,&xclass,length); | 135 | j=ASN1_get_object(&p,&len,&tag,&xclass,length); |
136 | #ifdef LINT | 136 | #ifdef LINT |
137 | j=j; | 137 | j=j; |
138 | #endif | 138 | #endif |
139 | if (j & 0x80) | 139 | if (j & 0x80) |
140 | { | 140 | { |
141 | if (BIO_write(bp,"Error in encoding\n",18) <= 0) | 141 | if (BIO_write(bp,"Error in encoding\n",18) <= 0) |
142 | goto end; | 142 | goto end; |
143 | ret=0; | 143 | ret=0; |
144 | goto end; | 144 | goto end; |
145 | } | 145 | } |
146 | hl=(p-op); | 146 | hl=(p-op); |
147 | length-=hl; | 147 | length-=hl; |
148 | /* if j == 0x21 it is a constructed indefinite length object */ | 148 | /* if j == 0x21 it is a constructed indefinite length object */ |
@@ -150,57 +150,57 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offse | |||
150 | <= 0) goto end; | 150 | <= 0) goto end; |
151 | 151 | ||
152 | if (j != (V_ASN1_CONSTRUCTED | 1)) | 152 | if (j != (V_ASN1_CONSTRUCTED | 1)) |
153 | { | 153 | { |
154 | if (BIO_printf(bp,"d=%-2d hl=%ld l=%4ld ", | 154 | if (BIO_printf(bp,"d=%-2d hl=%ld l=%4ld ", |
155 | depth,(long)hl,len) <= 0) | 155 | depth,(long)hl,len) <= 0) |
156 | goto end; | 156 | goto end; |
157 | } | 157 | } |
158 | else | 158 | else |
159 | { | 159 | { |
160 | if (BIO_printf(bp,"d=%-2d hl=%ld l=inf ", | 160 | if (BIO_printf(bp,"d=%-2d hl=%ld l=inf ", |
161 | depth,(long)hl) <= 0) | 161 | depth,(long)hl) <= 0) |
162 | goto end; | 162 | goto end; |
163 | } | 163 | } |
164 | if (!asn1_print_info(bp,tag,xclass,j,(indent)?depth:0)) | 164 | if (!asn1_print_info(bp,tag,xclass,j,(indent)?depth:0)) |
165 | goto end; | 165 | goto end; |
166 | if (j & V_ASN1_CONSTRUCTED) | 166 | if (j & V_ASN1_CONSTRUCTED) |
167 | { | 167 | { |
168 | ep=p+len; | 168 | ep=p+len; |
169 | if (BIO_write(bp,"\n",1) <= 0) goto end; | 169 | if (BIO_write(bp,"\n",1) <= 0) goto end; |
170 | if (len > length) | 170 | if (len > length) |
171 | { | 171 | { |
172 | BIO_printf(bp, | 172 | BIO_printf(bp, |
173 | "length is greater than %ld\n",length); | 173 | "length is greater than %ld\n",length); |
174 | ret=0; | 174 | ret=0; |
175 | goto end; | 175 | goto end; |
176 | } | 176 | } |
177 | if ((j == 0x21) && (len == 0)) | 177 | if ((j == 0x21) && (len == 0)) |
178 | { | 178 | { |
179 | for (;;) | 179 | for (;;) |
180 | { | 180 | { |
181 | r=asn1_parse2(bp,&p,(long)(tot-p), | 181 | r=asn1_parse2(bp,&p,(long)(tot-p), |
182 | offset+(p - *pp),depth+1, | 182 | offset+(p - *pp),depth+1, |
183 | indent,dump); | 183 | indent,dump); |
184 | if (r == 0) { ret=0; goto end; } | 184 | if (r == 0) { ret=0; goto end; } |
185 | if ((r == 2) || (p >= tot)) break; | 185 | if ((r == 2) || (p >= tot)) break; |
186 | } | ||
187 | } | 186 | } |
187 | } | ||
188 | else | 188 | else |
189 | while (p < ep) | 189 | while (p < ep) |
190 | { | 190 | { |
191 | r=asn1_parse2(bp,&p,(long)len, | 191 | r=asn1_parse2(bp,&p,(long)len, |
192 | offset+(p - *pp),depth+1, | 192 | offset+(p - *pp),depth+1, |
193 | indent,dump); | 193 | indent,dump); |
194 | if (r == 0) { ret=0; goto end; } | 194 | if (r == 0) { ret=0; goto end; } |
195 | } | 195 | } |
196 | } | 196 | } |
197 | else if (xclass != 0) | 197 | else if (xclass != 0) |
198 | { | 198 | { |
199 | p+=len; | 199 | p+=len; |
200 | if (BIO_write(bp,"\n",1) <= 0) goto end; | 200 | if (BIO_write(bp,"\n",1) <= 0) goto end; |
201 | } | 201 | } |
202 | else | 202 | else |
203 | { | 203 | { |
204 | nl=0; | 204 | nl=0; |
205 | if ( (tag == V_ASN1_PRINTABLESTRING) || | 205 | if ( (tag == V_ASN1_PRINTABLESTRING) || |
206 | (tag == V_ASN1_T61STRING) || | 206 | (tag == V_ASN1_T61STRING) || |
@@ -210,97 +210,97 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offse | |||
210 | (tag == V_ASN1_UTF8STRING) || | 210 | (tag == V_ASN1_UTF8STRING) || |
211 | (tag == V_ASN1_UTCTIME) || | 211 | (tag == V_ASN1_UTCTIME) || |
212 | (tag == V_ASN1_GENERALIZEDTIME)) | 212 | (tag == V_ASN1_GENERALIZEDTIME)) |
213 | { | 213 | { |
214 | if (BIO_write(bp,":",1) <= 0) goto end; | 214 | if (BIO_write(bp,":",1) <= 0) goto end; |
215 | if ((len > 0) && | 215 | if ((len > 0) && |
216 | BIO_write(bp,(const char *)p,(int)len) | 216 | BIO_write(bp,(const char *)p,(int)len) |
217 | != (int)len) | 217 | != (int)len) |
218 | goto end; | 218 | goto end; |
219 | } | 219 | } |
220 | else if (tag == V_ASN1_OBJECT) | 220 | else if (tag == V_ASN1_OBJECT) |
221 | { | 221 | { |
222 | opp=op; | 222 | opp=op; |
223 | if (d2i_ASN1_OBJECT(&o,&opp,len+hl) != NULL) | 223 | if (d2i_ASN1_OBJECT(&o,&opp,len+hl) != NULL) |
224 | { | 224 | { |
225 | if (BIO_write(bp,":",1) <= 0) goto end; | 225 | if (BIO_write(bp,":",1) <= 0) goto end; |
226 | i2a_ASN1_OBJECT(bp,o); | 226 | i2a_ASN1_OBJECT(bp,o); |
227 | } | 227 | } |
228 | else | 228 | else |
229 | { | 229 | { |
230 | if (BIO_write(bp,":BAD OBJECT",11) <= 0) | 230 | if (BIO_write(bp,":BAD OBJECT",11) <= 0) |
231 | goto end; | 231 | goto end; |
232 | } | ||
233 | } | 232 | } |
233 | } | ||
234 | else if (tag == V_ASN1_BOOLEAN) | 234 | else if (tag == V_ASN1_BOOLEAN) |
235 | { | 235 | { |
236 | int ii; | 236 | int ii; |
237 | 237 | ||
238 | opp=op; | 238 | opp=op; |
239 | ii=d2i_ASN1_BOOLEAN(NULL,&opp,len+hl); | 239 | ii=d2i_ASN1_BOOLEAN(NULL,&opp,len+hl); |
240 | if (ii < 0) | 240 | if (ii < 0) |
241 | { | 241 | { |
242 | if (BIO_write(bp,"Bad boolean\n",12) <= 0) | 242 | if (BIO_write(bp,"Bad boolean\n",12) <= 0) |
243 | goto end; | 243 | goto end; |
244 | } | ||
245 | BIO_printf(bp,":%d",ii); | ||
246 | } | 244 | } |
245 | BIO_printf(bp,":%d",ii); | ||
246 | } | ||
247 | else if (tag == V_ASN1_BMPSTRING) | 247 | else if (tag == V_ASN1_BMPSTRING) |
248 | { | 248 | { |
249 | /* do the BMP thang */ | 249 | /* do the BMP thang */ |
250 | } | 250 | } |
251 | else if (tag == V_ASN1_OCTET_STRING) | 251 | else if (tag == V_ASN1_OCTET_STRING) |
252 | { | 252 | { |
253 | int i,printable=1; | 253 | int i,printable=1; |
254 | 254 | ||
255 | opp=op; | 255 | opp=op; |
256 | os=d2i_ASN1_OCTET_STRING(NULL,&opp,len+hl); | 256 | os=d2i_ASN1_OCTET_STRING(NULL,&opp,len+hl); |
257 | if (os != NULL && os->length > 0) | 257 | if (os != NULL && os->length > 0) |
258 | { | 258 | { |
259 | opp = os->data; | 259 | opp = os->data; |
260 | /* testing whether the octet string is | 260 | /* testing whether the octet string is |
261 | * printable */ | 261 | * printable */ |
262 | for (i=0; i<os->length; i++) | 262 | for (i=0; i<os->length; i++) |
263 | { | 263 | { |
264 | if (( (opp[i] < ' ') && | 264 | if (( (opp[i] < ' ') && |
265 | (opp[i] != '\n') && | 265 | (opp[i] != '\n') && |
266 | (opp[i] != '\r') && | 266 | (opp[i] != '\r') && |
267 | (opp[i] != '\t')) || | 267 | (opp[i] != '\t')) || |
268 | (opp[i] > '~')) | 268 | (opp[i] > '~')) |
269 | { | 269 | { |
270 | printable=0; | 270 | printable=0; |
271 | break; | 271 | break; |
272 | } | ||
273 | } | 272 | } |
273 | } | ||
274 | if (printable) | 274 | if (printable) |
275 | /* printable string */ | 275 | /* printable string */ |
276 | { | 276 | { |
277 | if (BIO_write(bp,":",1) <= 0) | 277 | if (BIO_write(bp,":",1) <= 0) |
278 | goto end; | 278 | goto end; |
279 | if (BIO_write(bp,(const char *)opp, | 279 | if (BIO_write(bp,(const char *)opp, |
280 | os->length) <= 0) | 280 | os->length) <= 0) |
281 | goto end; | 281 | goto end; |
282 | } | 282 | } |
283 | else if (!dump) | 283 | else if (!dump) |
284 | /* not printable => print octet string | 284 | /* not printable => print octet string |
285 | * as hex dump */ | 285 | * as hex dump */ |
286 | { | 286 | { |
287 | if (BIO_write(bp,"[HEX DUMP]:",11) <= 0) | 287 | if (BIO_write(bp,"[HEX DUMP]:",11) <= 0) |
288 | goto end; | 288 | goto end; |
289 | for (i=0; i<os->length; i++) | 289 | for (i=0; i<os->length; i++) |
290 | { | 290 | { |
291 | if (BIO_printf(bp,"%02X" | 291 | if (BIO_printf(bp,"%02X" |
292 | , opp[i]) <= 0) | 292 | , opp[i]) <= 0) |
293 | goto end; | 293 | goto end; |
294 | } | ||
295 | } | 294 | } |
295 | } | ||
296 | else | 296 | else |
297 | /* print the normal dump */ | 297 | /* print the normal dump */ |
298 | { | 298 | { |
299 | if (!nl) | 299 | if (!nl) |
300 | { | 300 | { |
301 | if (BIO_write(bp,"\n",1) <= 0) | 301 | if (BIO_write(bp,"\n",1) <= 0) |
302 | goto end; | 302 | goto end; |
303 | } | 303 | } |
304 | if (BIO_dump_indent(bp, | 304 | if (BIO_dump_indent(bp, |
305 | (const char *)opp, | 305 | (const char *)opp, |
306 | ((dump == -1 || dump > | 306 | ((dump == -1 || dump > |
@@ -308,112 +308,112 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offse | |||
308 | dump_indent) <= 0) | 308 | dump_indent) <= 0) |
309 | goto end; | 309 | goto end; |
310 | nl=1; | 310 | nl=1; |
311 | } | ||
312 | } | 311 | } |
312 | } | ||
313 | if (os != NULL) | 313 | if (os != NULL) |
314 | { | 314 | { |
315 | M_ASN1_OCTET_STRING_free(os); | 315 | M_ASN1_OCTET_STRING_free(os); |
316 | os=NULL; | 316 | os=NULL; |
317 | } | ||
318 | } | 317 | } |
318 | } | ||
319 | else if (tag == V_ASN1_INTEGER) | 319 | else if (tag == V_ASN1_INTEGER) |
320 | { | 320 | { |
321 | ASN1_INTEGER *bs; | 321 | ASN1_INTEGER *bs; |
322 | int i; | 322 | int i; |
323 | 323 | ||
324 | opp=op; | 324 | opp=op; |
325 | bs=d2i_ASN1_INTEGER(NULL,&opp,len+hl); | 325 | bs=d2i_ASN1_INTEGER(NULL,&opp,len+hl); |
326 | if (bs != NULL) | 326 | if (bs != NULL) |
327 | { | 327 | { |
328 | if (BIO_write(bp,":",1) <= 0) goto end; | 328 | if (BIO_write(bp,":",1) <= 0) goto end; |
329 | if (bs->type == V_ASN1_NEG_INTEGER) | 329 | if (bs->type == V_ASN1_NEG_INTEGER) |
330 | if (BIO_write(bp,"-",1) <= 0) | 330 | if (BIO_write(bp,"-",1) <= 0) |
331 | goto end; | 331 | goto end; |
332 | for (i=0; i<bs->length; i++) | 332 | for (i=0; i<bs->length; i++) |
333 | { | 333 | { |
334 | if (BIO_printf(bp,"%02X", | 334 | if (BIO_printf(bp,"%02X", |
335 | bs->data[i]) <= 0) | 335 | bs->data[i]) <= 0) |
336 | goto end; | 336 | goto end; |
337 | } | 337 | } |
338 | if (bs->length == 0) | 338 | if (bs->length == 0) |
339 | { | 339 | { |
340 | if (BIO_write(bp,"00",2) <= 0) | 340 | if (BIO_write(bp,"00",2) <= 0) |
341 | goto end; | 341 | goto end; |
342 | } | ||
343 | } | 342 | } |
343 | } | ||
344 | else | 344 | else |
345 | { | 345 | { |
346 | if (BIO_write(bp,"BAD INTEGER",11) <= 0) | 346 | if (BIO_write(bp,"BAD INTEGER",11) <= 0) |
347 | goto end; | 347 | goto end; |
348 | } | ||
349 | M_ASN1_INTEGER_free(bs); | ||
350 | } | 348 | } |
349 | M_ASN1_INTEGER_free(bs); | ||
350 | } | ||
351 | else if (tag == V_ASN1_ENUMERATED) | 351 | else if (tag == V_ASN1_ENUMERATED) |
352 | { | 352 | { |
353 | ASN1_ENUMERATED *bs; | 353 | ASN1_ENUMERATED *bs; |
354 | int i; | 354 | int i; |
355 | 355 | ||
356 | opp=op; | 356 | opp=op; |
357 | bs=d2i_ASN1_ENUMERATED(NULL,&opp,len+hl); | 357 | bs=d2i_ASN1_ENUMERATED(NULL,&opp,len+hl); |
358 | if (bs != NULL) | 358 | if (bs != NULL) |
359 | { | 359 | { |
360 | if (BIO_write(bp,":",1) <= 0) goto end; | 360 | if (BIO_write(bp,":",1) <= 0) goto end; |
361 | if (bs->type == V_ASN1_NEG_ENUMERATED) | 361 | if (bs->type == V_ASN1_NEG_ENUMERATED) |
362 | if (BIO_write(bp,"-",1) <= 0) | 362 | if (BIO_write(bp,"-",1) <= 0) |
363 | goto end; | 363 | goto end; |
364 | for (i=0; i<bs->length; i++) | 364 | for (i=0; i<bs->length; i++) |
365 | { | 365 | { |
366 | if (BIO_printf(bp,"%02X", | 366 | if (BIO_printf(bp,"%02X", |
367 | bs->data[i]) <= 0) | 367 | bs->data[i]) <= 0) |
368 | goto end; | 368 | goto end; |
369 | } | 369 | } |
370 | if (bs->length == 0) | 370 | if (bs->length == 0) |
371 | { | 371 | { |
372 | if (BIO_write(bp,"00",2) <= 0) | 372 | if (BIO_write(bp,"00",2) <= 0) |
373 | goto end; | 373 | goto end; |
374 | } | ||
375 | } | 374 | } |
375 | } | ||
376 | else | 376 | else |
377 | { | 377 | { |
378 | if (BIO_write(bp,"BAD ENUMERATED",14) <= 0) | 378 | if (BIO_write(bp,"BAD ENUMERATED",14) <= 0) |
379 | goto end; | 379 | goto end; |
380 | } | ||
381 | M_ASN1_ENUMERATED_free(bs); | ||
382 | } | 380 | } |
381 | M_ASN1_ENUMERATED_free(bs); | ||
382 | } | ||
383 | else if (len > 0 && dump) | 383 | else if (len > 0 && dump) |
384 | { | 384 | { |
385 | if (!nl) | 385 | if (!nl) |
386 | { | 386 | { |
387 | if (BIO_write(bp,"\n",1) <= 0) | 387 | if (BIO_write(bp,"\n",1) <= 0) |
388 | goto end; | 388 | goto end; |
389 | } | 389 | } |
390 | if (BIO_dump_indent(bp,(const char *)p, | 390 | if (BIO_dump_indent(bp,(const char *)p, |
391 | ((dump == -1 || dump > len)?len:dump), | 391 | ((dump == -1 || dump > len)?len:dump), |
392 | dump_indent) <= 0) | 392 | dump_indent) <= 0) |
393 | goto end; | 393 | goto end; |
394 | nl=1; | 394 | nl=1; |
395 | } | 395 | } |
396 | 396 | ||
397 | if (!nl) | 397 | if (!nl) |
398 | { | 398 | { |
399 | if (BIO_write(bp,"\n",1) <= 0) goto end; | 399 | if (BIO_write(bp,"\n",1) <= 0) goto end; |
400 | } | 400 | } |
401 | p+=len; | 401 | p+=len; |
402 | if ((tag == V_ASN1_EOC) && (xclass == 0)) | 402 | if ((tag == V_ASN1_EOC) && (xclass == 0)) |
403 | { | 403 | { |
404 | ret=2; /* End of sequence */ | 404 | ret=2; /* End of sequence */ |
405 | goto end; | 405 | goto end; |
406 | } | ||
407 | } | 406 | } |
408 | length-=len; | ||
409 | } | 407 | } |
408 | length-=len; | ||
409 | } | ||
410 | ret=1; | 410 | ret=1; |
411 | end: | 411 | end: |
412 | if (o != NULL) ASN1_OBJECT_free(o); | 412 | if (o != NULL) ASN1_OBJECT_free(o); |
413 | if (os != NULL) M_ASN1_OCTET_STRING_free(os); | 413 | if (os != NULL) M_ASN1_OCTET_STRING_free(os); |
414 | *pp=p; | 414 | *pp=p; |
415 | return(ret); | 415 | return(ret); |
416 | } | 416 | } |
417 | 417 | ||
418 | const char *ASN1_tag2str(int tag) | 418 | const char *ASN1_tag2str(int tag) |
419 | { | 419 | { |
@@ -426,7 +426,7 @@ const char *ASN1_tag2str(int tag) | |||
426 | "VIDEOTEXSTRING", "IA5STRING", "UTCTIME","GENERALIZEDTIME", /* 21-24 */ | 426 | "VIDEOTEXSTRING", "IA5STRING", "UTCTIME","GENERALIZEDTIME", /* 21-24 */ |
427 | "GRAPHICSTRING", "VISIBLESTRING", "GENERALSTRING", /* 25-27 */ | 427 | "GRAPHICSTRING", "VISIBLESTRING", "GENERALSTRING", /* 25-27 */ |
428 | "UNIVERSALSTRING", "<ASN1 29>", "BMPSTRING" /* 28-30 */ | 428 | "UNIVERSALSTRING", "<ASN1 29>", "BMPSTRING" /* 28-30 */ |
429 | }; | 429 | }; |
430 | 430 | ||
431 | if((tag == V_ASN1_NEG_INTEGER) || (tag == V_ASN1_NEG_ENUMERATED)) | 431 | if((tag == V_ASN1_NEG_INTEGER) || (tag == V_ASN1_NEG_ENUMERATED)) |
432 | tag &= ~0x100; | 432 | tag &= ~0x100; |
diff --git a/src/lib/libcrypto/asn1/asn_mime.c b/src/lib/libcrypto/asn1/asn_mime.c index 2b600ab411..011b97ff92 100644 --- a/src/lib/libcrypto/asn1/asn_mime.c +++ b/src/lib/libcrypto/asn1/asn_mime.c | |||
@@ -114,48 +114,48 @@ static void mime_hdr_free(MIME_HEADER *hdr); | |||
114 | 114 | ||
115 | int i2d_ASN1_bio_stream(BIO *out, ASN1_VALUE *val, BIO *in, int flags, | 115 | int i2d_ASN1_bio_stream(BIO *out, ASN1_VALUE *val, BIO *in, int flags, |
116 | const ASN1_ITEM *it) | 116 | const ASN1_ITEM *it) |
117 | { | 117 | { |
118 | /* If streaming create stream BIO and copy all content through it */ | 118 | /* If streaming create stream BIO and copy all content through it */ |
119 | if (flags & SMIME_STREAM) | 119 | if (flags & SMIME_STREAM) |
120 | { | 120 | { |
121 | BIO *bio, *tbio; | 121 | BIO *bio, *tbio; |
122 | bio = BIO_new_NDEF(out, val, it); | 122 | bio = BIO_new_NDEF(out, val, it); |
123 | if (!bio) | 123 | if (!bio) |
124 | { | 124 | { |
125 | ASN1err(ASN1_F_I2D_ASN1_BIO_STREAM,ERR_R_MALLOC_FAILURE); | 125 | ASN1err(ASN1_F_I2D_ASN1_BIO_STREAM,ERR_R_MALLOC_FAILURE); |
126 | return 0; | 126 | return 0; |
127 | } | 127 | } |
128 | SMIME_crlf_copy(in, bio, flags); | 128 | SMIME_crlf_copy(in, bio, flags); |
129 | (void)BIO_flush(bio); | 129 | (void)BIO_flush(bio); |
130 | /* Free up successive BIOs until we hit the old output BIO */ | 130 | /* Free up successive BIOs until we hit the old output BIO */ |
131 | do | 131 | do |
132 | { | 132 | { |
133 | tbio = BIO_pop(bio); | 133 | tbio = BIO_pop(bio); |
134 | BIO_free(bio); | 134 | BIO_free(bio); |
135 | bio = tbio; | 135 | bio = tbio; |
136 | } while (bio != out); | 136 | } while (bio != out); |
137 | } | 137 | } |
138 | /* else just write out ASN1 structure which will have all content | 138 | /* else just write out ASN1 structure which will have all content |
139 | * stored internally | 139 | * stored internally |
140 | */ | 140 | */ |
141 | else | 141 | else |
142 | ASN1_item_i2d_bio(it, out, val); | 142 | ASN1_item_i2d_bio(it, out, val); |
143 | return 1; | 143 | return 1; |
144 | } | 144 | } |
145 | 145 | ||
146 | /* Base 64 read and write of ASN1 structure */ | 146 | /* Base 64 read and write of ASN1 structure */ |
147 | 147 | ||
148 | static int B64_write_ASN1(BIO *out, ASN1_VALUE *val, BIO *in, int flags, | 148 | static int B64_write_ASN1(BIO *out, ASN1_VALUE *val, BIO *in, int flags, |
149 | const ASN1_ITEM *it) | 149 | const ASN1_ITEM *it) |
150 | { | 150 | { |
151 | BIO *b64; | 151 | BIO *b64; |
152 | int r; | 152 | int r; |
153 | b64 = BIO_new(BIO_f_base64()); | 153 | b64 = BIO_new(BIO_f_base64()); |
154 | if(!b64) | 154 | if(!b64) |
155 | { | 155 | { |
156 | ASN1err(ASN1_F_B64_WRITE_ASN1,ERR_R_MALLOC_FAILURE); | 156 | ASN1err(ASN1_F_B64_WRITE_ASN1,ERR_R_MALLOC_FAILURE); |
157 | return 0; | 157 | return 0; |
158 | } | 158 | } |
159 | /* prepend the b64 BIO so all data is base64 encoded. | 159 | /* prepend the b64 BIO so all data is base64 encoded. |
160 | */ | 160 | */ |
161 | out = BIO_push(b64, out); | 161 | out = BIO_push(b64, out); |
@@ -164,20 +164,20 @@ static int B64_write_ASN1(BIO *out, ASN1_VALUE *val, BIO *in, int flags, | |||
164 | BIO_pop(out); | 164 | BIO_pop(out); |
165 | BIO_free(b64); | 165 | BIO_free(b64); |
166 | return r; | 166 | return r; |
167 | } | 167 | } |
168 | 168 | ||
169 | /* Streaming ASN1 PEM write */ | 169 | /* Streaming ASN1 PEM write */ |
170 | 170 | ||
171 | int PEM_write_bio_ASN1_stream(BIO *out, ASN1_VALUE *val, BIO *in, int flags, | 171 | int PEM_write_bio_ASN1_stream(BIO *out, ASN1_VALUE *val, BIO *in, int flags, |
172 | const char *hdr, | 172 | const char *hdr, |
173 | const ASN1_ITEM *it) | 173 | const ASN1_ITEM *it) |
174 | { | 174 | { |
175 | int r; | 175 | int r; |
176 | BIO_printf(out, "-----BEGIN %s-----\n", hdr); | 176 | BIO_printf(out, "-----BEGIN %s-----\n", hdr); |
177 | r = B64_write_ASN1(out, val, in, flags, it); | 177 | r = B64_write_ASN1(out, val, in, flags, it); |
178 | BIO_printf(out, "-----END %s-----\n", hdr); | 178 | BIO_printf(out, "-----END %s-----\n", hdr); |
179 | return r; | 179 | return r; |
180 | } | 180 | } |
181 | 181 | ||
182 | static ASN1_VALUE *b64_read_asn1(BIO *bio, const ASN1_ITEM *it) | 182 | static ASN1_VALUE *b64_read_asn1(BIO *bio, const ASN1_ITEM *it) |
183 | { | 183 | { |
@@ -186,7 +186,7 @@ static ASN1_VALUE *b64_read_asn1(BIO *bio, const ASN1_ITEM *it) | |||
186 | if(!(b64 = BIO_new(BIO_f_base64()))) { | 186 | if(!(b64 = BIO_new(BIO_f_base64()))) { |
187 | ASN1err(ASN1_F_B64_READ_ASN1,ERR_R_MALLOC_FAILURE); | 187 | ASN1err(ASN1_F_B64_READ_ASN1,ERR_R_MALLOC_FAILURE); |
188 | return 0; | 188 | return 0; |
189 | } | 189 | } |
190 | bio = BIO_push(b64, bio); | 190 | bio = BIO_push(b64, bio); |
191 | val = ASN1_item_d2i_bio(it, bio, NULL); | 191 | val = ASN1_item_d2i_bio(it, bio, NULL); |
192 | if(!val) | 192 | if(!val) |
@@ -200,34 +200,34 @@ static ASN1_VALUE *b64_read_asn1(BIO *bio, const ASN1_ITEM *it) | |||
200 | /* Generate the MIME "micalg" parameter from RFC3851, RFC4490 */ | 200 | /* Generate the MIME "micalg" parameter from RFC3851, RFC4490 */ |
201 | 201 | ||
202 | static int asn1_write_micalg(BIO *out, STACK_OF(X509_ALGOR) *mdalgs) | 202 | static int asn1_write_micalg(BIO *out, STACK_OF(X509_ALGOR) *mdalgs) |
203 | { | 203 | { |
204 | const EVP_MD *md; | 204 | const EVP_MD *md; |
205 | int i, have_unknown = 0, write_comma, ret = 0, md_nid; | 205 | int i, have_unknown = 0, write_comma, ret = 0, md_nid; |
206 | have_unknown = 0; | 206 | have_unknown = 0; |
207 | write_comma = 0; | 207 | write_comma = 0; |
208 | for (i = 0; i < sk_X509_ALGOR_num(mdalgs); i++) | 208 | for (i = 0; i < sk_X509_ALGOR_num(mdalgs); i++) |
209 | { | 209 | { |
210 | if (write_comma) | 210 | if (write_comma) |
211 | BIO_write(out, ",", 1); | 211 | BIO_write(out, ",", 1); |
212 | write_comma = 1; | 212 | write_comma = 1; |
213 | md_nid = OBJ_obj2nid(sk_X509_ALGOR_value(mdalgs, i)->algorithm); | 213 | md_nid = OBJ_obj2nid(sk_X509_ALGOR_value(mdalgs, i)->algorithm); |
214 | md = EVP_get_digestbynid(md_nid); | 214 | md = EVP_get_digestbynid(md_nid); |
215 | if (md && md->md_ctrl) | 215 | if (md && md->md_ctrl) |
216 | { | 216 | { |
217 | int rv; | 217 | int rv; |
218 | char *micstr; | 218 | char *micstr; |
219 | rv = md->md_ctrl(NULL, EVP_MD_CTRL_MICALG, 0, &micstr); | 219 | rv = md->md_ctrl(NULL, EVP_MD_CTRL_MICALG, 0, &micstr); |
220 | if (rv > 0) | 220 | if (rv > 0) |
221 | { | 221 | { |
222 | BIO_puts(out, micstr); | 222 | BIO_puts(out, micstr); |
223 | free(micstr); | 223 | free(micstr); |
224 | continue; | 224 | continue; |
225 | } | 225 | } |
226 | if (rv != -2) | 226 | if (rv != -2) |
227 | goto err; | 227 | goto err; |
228 | } | 228 | } |
229 | switch(md_nid) | 229 | switch(md_nid) |
230 | { | 230 | { |
231 | case NID_sha1: | 231 | case NID_sha1: |
232 | BIO_puts(out, "sha1"); | 232 | BIO_puts(out, "sha1"); |
233 | break; | 233 | break; |
@@ -257,21 +257,21 @@ static int asn1_write_micalg(BIO *out, STACK_OF(X509_ALGOR) *mdalgs) | |||
257 | if (have_unknown) | 257 | if (have_unknown) |
258 | write_comma = 0; | 258 | write_comma = 0; |
259 | else | 259 | else |
260 | { | 260 | { |
261 | BIO_puts(out, "unknown"); | 261 | BIO_puts(out, "unknown"); |
262 | have_unknown = 1; | 262 | have_unknown = 1; |
263 | } | 263 | } |
264 | break; | 264 | break; |
265 | 265 | ||
266 | } | ||
267 | } | 266 | } |
267 | } | ||
268 | 268 | ||
269 | ret = 1; | 269 | ret = 1; |
270 | err: | 270 | err: |
271 | 271 | ||
272 | return ret; | 272 | return ret; |
273 | 273 | ||
274 | } | 274 | } |
275 | 275 | ||
276 | /* SMIME sender */ | 276 | /* SMIME sender */ |
277 | 277 | ||
@@ -302,7 +302,7 @@ int SMIME_write_ASN1(BIO *bio, ASN1_VALUE *val, BIO *data, int flags, | |||
302 | if(c < 10) c += '0'; | 302 | if(c < 10) c += '0'; |
303 | else c += 'A' - 10; | 303 | else c += 'A' - 10; |
304 | bound[i] = c; | 304 | bound[i] = c; |
305 | } | 305 | } |
306 | bound[32] = 0; | 306 | bound[32] = 0; |
307 | BIO_printf(bio, "MIME-Version: 1.0%s", mime_eol); | 307 | BIO_printf(bio, "MIME-Version: 1.0%s", mime_eol); |
308 | BIO_printf(bio, "Content-Type: multipart/signed;"); | 308 | BIO_printf(bio, "Content-Type: multipart/signed;"); |
@@ -332,26 +332,26 @@ int SMIME_write_ASN1(BIO *bio, ASN1_VALUE *val, BIO *data, int flags, | |||
332 | BIO_printf(bio,"%s------%s--%s%s", mime_eol, bound, | 332 | BIO_printf(bio,"%s------%s--%s%s", mime_eol, bound, |
333 | mime_eol, mime_eol); | 333 | mime_eol, mime_eol); |
334 | return 1; | 334 | return 1; |
335 | } | 335 | } |
336 | 336 | ||
337 | /* Determine smime-type header */ | 337 | /* Determine smime-type header */ |
338 | 338 | ||
339 | if (ctype_nid == NID_pkcs7_enveloped) | 339 | if (ctype_nid == NID_pkcs7_enveloped) |
340 | msg_type = "enveloped-data"; | 340 | msg_type = "enveloped-data"; |
341 | else if (ctype_nid == NID_pkcs7_signed) | 341 | else if (ctype_nid == NID_pkcs7_signed) |
342 | { | 342 | { |
343 | if (econt_nid == NID_id_smime_ct_receipt) | 343 | if (econt_nid == NID_id_smime_ct_receipt) |
344 | msg_type = "signed-receipt"; | 344 | msg_type = "signed-receipt"; |
345 | else if (sk_X509_ALGOR_num(mdalgs) >= 0) | 345 | else if (sk_X509_ALGOR_num(mdalgs) >= 0) |
346 | msg_type = "signed-data"; | 346 | msg_type = "signed-data"; |
347 | else | 347 | else |
348 | msg_type = "certs-only"; | 348 | msg_type = "certs-only"; |
349 | } | 349 | } |
350 | else if (ctype_nid == NID_id_smime_ct_compressedData) | 350 | else if (ctype_nid == NID_id_smime_ct_compressedData) |
351 | { | 351 | { |
352 | msg_type = "compressed-data"; | 352 | msg_type = "compressed-data"; |
353 | cname = "smime.p7z"; | 353 | cname = "smime.p7z"; |
354 | } | 354 | } |
355 | /* MIME headers */ | 355 | /* MIME headers */ |
356 | BIO_printf(bio, "MIME-Version: 1.0%s", mime_eol); | 356 | BIO_printf(bio, "MIME-Version: 1.0%s", mime_eol); |
357 | BIO_printf(bio, "Content-Disposition: attachment;"); | 357 | BIO_printf(bio, "Content-Disposition: attachment;"); |
@@ -373,7 +373,7 @@ int SMIME_write_ASN1(BIO *bio, ASN1_VALUE *val, BIO *data, int flags, | |||
373 | 373 | ||
374 | static int asn1_output_data(BIO *out, BIO *data, ASN1_VALUE *val, int flags, | 374 | static int asn1_output_data(BIO *out, BIO *data, ASN1_VALUE *val, int flags, |
375 | const ASN1_ITEM *it) | 375 | const ASN1_ITEM *it) |
376 | { | 376 | { |
377 | BIO *tmpbio; | 377 | BIO *tmpbio; |
378 | const ASN1_AUX *aux = it->funcs; | 378 | const ASN1_AUX *aux = it->funcs; |
379 | ASN1_STREAM_ARG sarg; | 379 | ASN1_STREAM_ARG sarg; |
@@ -383,17 +383,17 @@ static int asn1_output_data(BIO *out, BIO *data, ASN1_VALUE *val, int flags, | |||
383 | * already set up to finalise when it is written through. | 383 | * already set up to finalise when it is written through. |
384 | */ | 384 | */ |
385 | if (!(flags & SMIME_DETACHED) || (flags & PKCS7_REUSE_DIGEST)) | 385 | if (!(flags & SMIME_DETACHED) || (flags & PKCS7_REUSE_DIGEST)) |
386 | { | 386 | { |
387 | SMIME_crlf_copy(data, out, flags); | 387 | SMIME_crlf_copy(data, out, flags); |
388 | return 1; | 388 | return 1; |
389 | } | 389 | } |
390 | 390 | ||
391 | if (!aux || !aux->asn1_cb) | 391 | if (!aux || !aux->asn1_cb) |
392 | { | 392 | { |
393 | ASN1err(ASN1_F_ASN1_OUTPUT_DATA, | 393 | ASN1err(ASN1_F_ASN1_OUTPUT_DATA, |
394 | ASN1_R_STREAMING_NOT_SUPPORTED); | 394 | ASN1_R_STREAMING_NOT_SUPPORTED); |
395 | return 0; | 395 | return 0; |
396 | } | 396 | } |
397 | 397 | ||
398 | sarg.out = out; | 398 | sarg.out = out; |
399 | sarg.ndef_bio = NULL; | 399 | sarg.ndef_bio = NULL; |
@@ -414,15 +414,15 @@ static int asn1_output_data(BIO *out, BIO *data, ASN1_VALUE *val, int flags, | |||
414 | /* Now remove any digests prepended to the BIO */ | 414 | /* Now remove any digests prepended to the BIO */ |
415 | 415 | ||
416 | while (sarg.ndef_bio != out) | 416 | while (sarg.ndef_bio != out) |
417 | { | 417 | { |
418 | tmpbio = BIO_pop(sarg.ndef_bio); | 418 | tmpbio = BIO_pop(sarg.ndef_bio); |
419 | BIO_free(sarg.ndef_bio); | 419 | BIO_free(sarg.ndef_bio); |
420 | sarg.ndef_bio = tmpbio; | 420 | sarg.ndef_bio = tmpbio; |
421 | } | 421 | } |
422 | 422 | ||
423 | return rv; | 423 | return rv; |
424 | 424 | ||
425 | } | 425 | } |
426 | 426 | ||
427 | /* SMIME reader: handle multipart/signed and opaque signing. | 427 | /* SMIME reader: handle multipart/signed and opaque signing. |
428 | * in multipart case the content is placed in a memory BIO | 428 | * in multipart case the content is placed in a memory BIO |
@@ -444,13 +444,13 @@ ASN1_VALUE *SMIME_read_ASN1(BIO *bio, BIO **bcont, const ASN1_ITEM *it) | |||
444 | if (!(headers = mime_parse_hdr(bio))) { | 444 | if (!(headers = mime_parse_hdr(bio))) { |
445 | ASN1err(ASN1_F_SMIME_READ_ASN1,ASN1_R_MIME_PARSE_ERROR); | 445 | ASN1err(ASN1_F_SMIME_READ_ASN1,ASN1_R_MIME_PARSE_ERROR); |
446 | return NULL; | 446 | return NULL; |
447 | } | 447 | } |
448 | 448 | ||
449 | if(!(hdr = mime_hdr_find(headers, "content-type")) || !hdr->value) { | 449 | if(!(hdr = mime_hdr_find(headers, "content-type")) || !hdr->value) { |
450 | sk_MIME_HEADER_pop_free(headers, mime_hdr_free); | 450 | sk_MIME_HEADER_pop_free(headers, mime_hdr_free); |
451 | ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_NO_CONTENT_TYPE); | 451 | ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_NO_CONTENT_TYPE); |
452 | return NULL; | 452 | return NULL; |
453 | } | 453 | } |
454 | 454 | ||
455 | /* Handle multipart/signed */ | 455 | /* Handle multipart/signed */ |
456 | 456 | ||
@@ -461,14 +461,14 @@ ASN1_VALUE *SMIME_read_ASN1(BIO *bio, BIO **bcont, const ASN1_ITEM *it) | |||
461 | sk_MIME_HEADER_pop_free(headers, mime_hdr_free); | 461 | sk_MIME_HEADER_pop_free(headers, mime_hdr_free); |
462 | ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_NO_MULTIPART_BOUNDARY); | 462 | ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_NO_MULTIPART_BOUNDARY); |
463 | return NULL; | 463 | return NULL; |
464 | } | 464 | } |
465 | ret = multi_split(bio, prm->param_value, &parts); | 465 | ret = multi_split(bio, prm->param_value, &parts); |
466 | sk_MIME_HEADER_pop_free(headers, mime_hdr_free); | 466 | sk_MIME_HEADER_pop_free(headers, mime_hdr_free); |
467 | if(!ret || (sk_BIO_num(parts) != 2) ) { | 467 | if(!ret || (sk_BIO_num(parts) != 2) ) { |
468 | ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_NO_MULTIPART_BODY_FAILURE); | 468 | ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_NO_MULTIPART_BODY_FAILURE); |
469 | sk_BIO_pop_free(parts, BIO_vfree); | 469 | sk_BIO_pop_free(parts, BIO_vfree); |
470 | return NULL; | 470 | return NULL; |
471 | } | 471 | } |
472 | 472 | ||
473 | /* Parse the signature piece */ | 473 | /* Parse the signature piece */ |
474 | asnin = sk_BIO_value(parts, 1); | 474 | asnin = sk_BIO_value(parts, 1); |
@@ -477,7 +477,7 @@ ASN1_VALUE *SMIME_read_ASN1(BIO *bio, BIO **bcont, const ASN1_ITEM *it) | |||
477 | ASN1err(ASN1_F_SMIME_READ_ASN1,ASN1_R_MIME_SIG_PARSE_ERROR); | 477 | ASN1err(ASN1_F_SMIME_READ_ASN1,ASN1_R_MIME_SIG_PARSE_ERROR); |
478 | sk_BIO_pop_free(parts, BIO_vfree); | 478 | sk_BIO_pop_free(parts, BIO_vfree); |
479 | return NULL; | 479 | return NULL; |
480 | } | 480 | } |
481 | 481 | ||
482 | /* Get content type */ | 482 | /* Get content type */ |
483 | 483 | ||
@@ -486,7 +486,7 @@ ASN1_VALUE *SMIME_read_ASN1(BIO *bio, BIO **bcont, const ASN1_ITEM *it) | |||
486 | sk_MIME_HEADER_pop_free(headers, mime_hdr_free); | 486 | sk_MIME_HEADER_pop_free(headers, mime_hdr_free); |
487 | ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_NO_SIG_CONTENT_TYPE); | 487 | ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_NO_SIG_CONTENT_TYPE); |
488 | return NULL; | 488 | return NULL; |
489 | } | 489 | } |
490 | 490 | ||
491 | if(strcmp(hdr->value, "application/x-pkcs7-signature") && | 491 | if(strcmp(hdr->value, "application/x-pkcs7-signature") && |
492 | strcmp(hdr->value, "application/pkcs7-signature")) { | 492 | strcmp(hdr->value, "application/pkcs7-signature")) { |
@@ -495,22 +495,22 @@ ASN1_VALUE *SMIME_read_ASN1(BIO *bio, BIO **bcont, const ASN1_ITEM *it) | |||
495 | sk_MIME_HEADER_pop_free(headers, mime_hdr_free); | 495 | sk_MIME_HEADER_pop_free(headers, mime_hdr_free); |
496 | sk_BIO_pop_free(parts, BIO_vfree); | 496 | sk_BIO_pop_free(parts, BIO_vfree); |
497 | return NULL; | 497 | return NULL; |
498 | } | 498 | } |
499 | sk_MIME_HEADER_pop_free(headers, mime_hdr_free); | 499 | sk_MIME_HEADER_pop_free(headers, mime_hdr_free); |
500 | /* Read in ASN1 */ | 500 | /* Read in ASN1 */ |
501 | if(!(val = b64_read_asn1(asnin, it))) { | 501 | if(!(val = b64_read_asn1(asnin, it))) { |
502 | ASN1err(ASN1_F_SMIME_READ_ASN1,ASN1_R_ASN1_SIG_PARSE_ERROR); | 502 | ASN1err(ASN1_F_SMIME_READ_ASN1,ASN1_R_ASN1_SIG_PARSE_ERROR); |
503 | sk_BIO_pop_free(parts, BIO_vfree); | 503 | sk_BIO_pop_free(parts, BIO_vfree); |
504 | return NULL; | 504 | return NULL; |
505 | } | 505 | } |
506 | 506 | ||
507 | if(bcont) { | 507 | if(bcont) { |
508 | *bcont = sk_BIO_value(parts, 0); | 508 | *bcont = sk_BIO_value(parts, 0); |
509 | BIO_free(asnin); | 509 | BIO_free(asnin); |
510 | sk_BIO_free(parts); | 510 | sk_BIO_free(parts); |
511 | } else sk_BIO_pop_free(parts, BIO_vfree); | 511 | } else sk_BIO_pop_free(parts, BIO_vfree); |
512 | return val; | 512 | return val; |
513 | } | 513 | } |
514 | 514 | ||
515 | /* OK, if not multipart/signed try opaque signature */ | 515 | /* OK, if not multipart/signed try opaque signature */ |
516 | 516 | ||
@@ -520,14 +520,14 @@ ASN1_VALUE *SMIME_read_ASN1(BIO *bio, BIO **bcont, const ASN1_ITEM *it) | |||
520 | ERR_add_error_data(2, "type: ", hdr->value); | 520 | ERR_add_error_data(2, "type: ", hdr->value); |
521 | sk_MIME_HEADER_pop_free(headers, mime_hdr_free); | 521 | sk_MIME_HEADER_pop_free(headers, mime_hdr_free); |
522 | return NULL; | 522 | return NULL; |
523 | } | 523 | } |
524 | 524 | ||
525 | sk_MIME_HEADER_pop_free(headers, mime_hdr_free); | 525 | sk_MIME_HEADER_pop_free(headers, mime_hdr_free); |
526 | 526 | ||
527 | if(!(val = b64_read_asn1(bio, it))) { | 527 | if(!(val = b64_read_asn1(bio, it))) { |
528 | ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_ASN1_PARSE_ERROR); | 528 | ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_ASN1_PARSE_ERROR); |
529 | return NULL; | 529 | return NULL; |
530 | } | 530 | } |
531 | return val; | 531 | return val; |
532 | 532 | ||
533 | } | 533 | } |
@@ -548,22 +548,22 @@ int SMIME_crlf_copy(BIO *in, BIO *out, int flags) | |||
548 | return 0; | 548 | return 0; |
549 | out = BIO_push(bf, out); | 549 | out = BIO_push(bf, out); |
550 | if(flags & SMIME_BINARY) | 550 | if(flags & SMIME_BINARY) |
551 | { | 551 | { |
552 | while((len = BIO_read(in, linebuf, MAX_SMLEN)) > 0) | 552 | while((len = BIO_read(in, linebuf, MAX_SMLEN)) > 0) |
553 | BIO_write(out, linebuf, len); | 553 | BIO_write(out, linebuf, len); |
554 | } | 554 | } |
555 | else | 555 | else |
556 | { | 556 | { |
557 | if(flags & SMIME_TEXT) | 557 | if(flags & SMIME_TEXT) |
558 | BIO_printf(out, "Content-Type: text/plain\r\n\r\n"); | 558 | BIO_printf(out, "Content-Type: text/plain\r\n\r\n"); |
559 | while ((len = BIO_gets(in, linebuf, MAX_SMLEN)) > 0) | 559 | while ((len = BIO_gets(in, linebuf, MAX_SMLEN)) > 0) |
560 | { | 560 | { |
561 | eol = strip_eol(linebuf, &len); | 561 | eol = strip_eol(linebuf, &len); |
562 | if (len) | 562 | if (len) |
563 | BIO_write(out, linebuf, len); | 563 | BIO_write(out, linebuf, len); |
564 | if(eol) BIO_write(out, "\r\n", 2); | 564 | if(eol) BIO_write(out, "\r\n", 2); |
565 | } | ||
566 | } | 565 | } |
566 | } | ||
567 | (void)BIO_flush(out); | 567 | (void)BIO_flush(out); |
568 | BIO_pop(out); | 568 | BIO_pop(out); |
569 | BIO_free(bf); | 569 | BIO_free(bf); |
@@ -581,18 +581,18 @@ int SMIME_text(BIO *in, BIO *out) | |||
581 | if (!(headers = mime_parse_hdr(in))) { | 581 | if (!(headers = mime_parse_hdr(in))) { |
582 | ASN1err(ASN1_F_SMIME_TEXT,ASN1_R_MIME_PARSE_ERROR); | 582 | ASN1err(ASN1_F_SMIME_TEXT,ASN1_R_MIME_PARSE_ERROR); |
583 | return 0; | 583 | return 0; |
584 | } | 584 | } |
585 | if(!(hdr = mime_hdr_find(headers, "content-type")) || !hdr->value) { | 585 | if(!(hdr = mime_hdr_find(headers, "content-type")) || !hdr->value) { |
586 | ASN1err(ASN1_F_SMIME_TEXT,ASN1_R_MIME_NO_CONTENT_TYPE); | 586 | ASN1err(ASN1_F_SMIME_TEXT,ASN1_R_MIME_NO_CONTENT_TYPE); |
587 | sk_MIME_HEADER_pop_free(headers, mime_hdr_free); | 587 | sk_MIME_HEADER_pop_free(headers, mime_hdr_free); |
588 | return 0; | 588 | return 0; |
589 | } | 589 | } |
590 | if (strcmp (hdr->value, "text/plain")) { | 590 | if (strcmp (hdr->value, "text/plain")) { |
591 | ASN1err(ASN1_F_SMIME_TEXT,ASN1_R_INVALID_MIME_TYPE); | 591 | ASN1err(ASN1_F_SMIME_TEXT,ASN1_R_INVALID_MIME_TYPE); |
592 | ERR_add_error_data(2, "type: ", hdr->value); | 592 | ERR_add_error_data(2, "type: ", hdr->value); |
593 | sk_MIME_HEADER_pop_free(headers, mime_hdr_free); | 593 | sk_MIME_HEADER_pop_free(headers, mime_hdr_free); |
594 | return 0; | 594 | return 0; |
595 | } | 595 | } |
596 | sk_MIME_HEADER_pop_free(headers, mime_hdr_free); | 596 | sk_MIME_HEADER_pop_free(headers, mime_hdr_free); |
597 | while ((len = BIO_read(in, iobuf, sizeof(iobuf))) > 0) | 597 | while ((len = BIO_read(in, iobuf, sizeof(iobuf))) > 0) |
598 | BIO_write(out, iobuf, len); | 598 | BIO_write(out, iobuf, len); |
@@ -625,10 +625,10 @@ static int multi_split(BIO *bio, char *bound, STACK_OF(BIO) **ret) | |||
625 | if(state == 1) { | 625 | if(state == 1) { |
626 | first = 1; | 626 | first = 1; |
627 | part++; | 627 | part++; |
628 | } else if(state == 2) { | 628 | } else if(state == 2) { |
629 | sk_BIO_push(parts, bpart); | 629 | sk_BIO_push(parts, bpart); |
630 | return 1; | 630 | return 1; |
631 | } else if(part) { | 631 | } else if(part) { |
632 | /* Strip CR+LF from linebuf */ | 632 | /* Strip CR+LF from linebuf */ |
633 | next_eol = strip_eol(linebuf, &len); | 633 | next_eol = strip_eol(linebuf, &len); |
634 | if(first) { | 634 | if(first) { |
@@ -636,13 +636,13 @@ static int multi_split(BIO *bio, char *bound, STACK_OF(BIO) **ret) | |||
636 | if(bpart) sk_BIO_push(parts, bpart); | 636 | if(bpart) sk_BIO_push(parts, bpart); |
637 | bpart = BIO_new(BIO_s_mem()); | 637 | bpart = BIO_new(BIO_s_mem()); |
638 | BIO_set_mem_eof_return(bpart, 0); | 638 | BIO_set_mem_eof_return(bpart, 0); |
639 | } else if (eol) | 639 | } else if (eol) |
640 | BIO_write(bpart, "\r\n", 2); | 640 | BIO_write(bpart, "\r\n", 2); |
641 | eol = next_eol; | 641 | eol = next_eol; |
642 | if (len) | 642 | if (len) |
643 | BIO_write(bpart, linebuf, len); | 643 | BIO_write(bpart, linebuf, len); |
644 | } | ||
645 | } | 644 | } |
645 | } | ||
646 | return 0; | 646 | return 0; |
647 | } | 647 | } |
648 | 648 | ||
@@ -686,7 +686,7 @@ static STACK_OF(MIME_HEADER) *mime_parse_hdr(BIO *bio) | |||
686 | *p = 0; | 686 | *p = 0; |
687 | ntmp = strip_ends(q); | 687 | ntmp = strip_ends(q); |
688 | q = p + 1; | 688 | q = p + 1; |
689 | } | 689 | } |
690 | break; | 690 | break; |
691 | 691 | ||
692 | case MIME_TYPE: | 692 | case MIME_TYPE: |
@@ -698,16 +698,16 @@ static STACK_OF(MIME_HEADER) *mime_parse_hdr(BIO *bio) | |||
698 | ntmp = NULL; | 698 | ntmp = NULL; |
699 | q = p + 1; | 699 | q = p + 1; |
700 | state = MIME_NAME; | 700 | state = MIME_NAME; |
701 | } else if(c == '(') { | 701 | } else if(c == '(') { |
702 | save_state = state; | 702 | save_state = state; |
703 | state = MIME_COMMENT; | 703 | state = MIME_COMMENT; |
704 | } | 704 | } |
705 | break; | 705 | break; |
706 | 706 | ||
707 | case MIME_COMMENT: | 707 | case MIME_COMMENT: |
708 | if(c == ')') { | 708 | if(c == ')') { |
709 | state = save_state; | 709 | state = save_state; |
710 | } | 710 | } |
711 | break; | 711 | break; |
712 | 712 | ||
713 | case MIME_NAME: | 713 | case MIME_NAME: |
@@ -716,7 +716,7 @@ static STACK_OF(MIME_HEADER) *mime_parse_hdr(BIO *bio) | |||
716 | *p = 0; | 716 | *p = 0; |
717 | ntmp = strip_ends(q); | 717 | ntmp = strip_ends(q); |
718 | q = p + 1; | 718 | q = p + 1; |
719 | } | 719 | } |
720 | break ; | 720 | break ; |
721 | 721 | ||
722 | case MIME_VALUE: | 722 | case MIME_VALUE: |
@@ -726,28 +726,28 @@ static STACK_OF(MIME_HEADER) *mime_parse_hdr(BIO *bio) | |||
726 | mime_hdr_addparam(mhdr, ntmp, strip_ends(q)); | 726 | mime_hdr_addparam(mhdr, ntmp, strip_ends(q)); |
727 | ntmp = NULL; | 727 | ntmp = NULL; |
728 | q = p + 1; | 728 | q = p + 1; |
729 | } else if (c == '"') { | 729 | } else if (c == '"') { |
730 | mime_debug("Found Quote\n"); | 730 | mime_debug("Found Quote\n"); |
731 | state = MIME_QUOTE; | 731 | state = MIME_QUOTE; |
732 | } else if(c == '(') { | 732 | } else if(c == '(') { |
733 | save_state = state; | 733 | save_state = state; |
734 | state = MIME_COMMENT; | 734 | state = MIME_COMMENT; |
735 | } | 735 | } |
736 | break; | 736 | break; |
737 | 737 | ||
738 | case MIME_QUOTE: | 738 | case MIME_QUOTE: |
739 | if(c == '"') { | 739 | if(c == '"') { |
740 | mime_debug("Found Match Quote\n"); | 740 | mime_debug("Found Match Quote\n"); |
741 | state = MIME_VALUE; | 741 | state = MIME_VALUE; |
742 | } | ||
743 | break; | ||
744 | } | 742 | } |
743 | break; | ||
745 | } | 744 | } |
745 | } | ||
746 | 746 | ||
747 | if(state == MIME_TYPE) { | 747 | if(state == MIME_TYPE) { |
748 | mhdr = mime_hdr_new(ntmp, strip_ends(q)); | 748 | mhdr = mime_hdr_new(ntmp, strip_ends(q)); |
749 | sk_MIME_HEADER_push(headers, mhdr); | 749 | sk_MIME_HEADER_push(headers, mhdr); |
750 | } else if(state == MIME_VALUE) | 750 | } else if(state == MIME_VALUE) |
751 | mime_hdr_addparam(mhdr, ntmp, strip_ends(q)); | 751 | mime_hdr_addparam(mhdr, ntmp, strip_ends(q)); |
752 | if(p == linebuf) break; /* Blank line means end of headers */ | 752 | if(p == linebuf) break; /* Blank line means end of headers */ |
753 | } | 753 | } |
@@ -772,9 +772,9 @@ static char *strip_start(char *name) | |||
772 | if(p[1]) return p + 1; | 772 | if(p[1]) return p + 1; |
773 | /* Else null string */ | 773 | /* Else null string */ |
774 | return NULL; | 774 | return NULL; |
775 | } | ||
776 | if(!isspace((unsigned char)c)) return p; | ||
777 | } | 775 | } |
776 | if(!isspace((unsigned char)c)) return p; | ||
777 | } | ||
778 | return NULL; | 778 | return NULL; |
779 | } | 779 | } |
780 | 780 | ||
@@ -790,10 +790,10 @@ static char *strip_end(char *name) | |||
790 | if(p - 1 == name) return NULL; | 790 | if(p - 1 == name) return NULL; |
791 | *p = 0; | 791 | *p = 0; |
792 | return name; | 792 | return name; |
793 | } | 793 | } |
794 | if(isspace((unsigned char)c)) *p = 0; | 794 | if(isspace((unsigned char)c)) *p = 0; |
795 | else return name; | 795 | else return name; |
796 | } | 796 | } |
797 | return NULL; | 797 | return NULL; |
798 | } | 798 | } |
799 | 799 | ||
@@ -809,9 +809,9 @@ static MIME_HEADER *mime_hdr_new(char *name, char *value) | |||
809 | if(isupper(c)) { | 809 | if(isupper(c)) { |
810 | c = tolower(c); | 810 | c = tolower(c); |
811 | *p = c; | 811 | *p = c; |
812 | } | ||
813 | } | 812 | } |
814 | } else tmpname = NULL; | 813 | } |
814 | } else tmpname = NULL; | ||
815 | if(value) { | 815 | if(value) { |
816 | if(!(tmpval = BUF_strdup(value))) return NULL; | 816 | if(!(tmpval = BUF_strdup(value))) return NULL; |
817 | for(p = tmpval ; *p; p++) { | 817 | for(p = tmpval ; *p; p++) { |
@@ -819,20 +819,20 @@ static MIME_HEADER *mime_hdr_new(char *name, char *value) | |||
819 | if(isupper(c)) { | 819 | if(isupper(c)) { |
820 | c = tolower(c); | 820 | c = tolower(c); |
821 | *p = c; | 821 | *p = c; |
822 | } | ||
823 | } | 822 | } |
824 | } else tmpval = NULL; | 823 | } |
824 | } else tmpval = NULL; | ||
825 | mhdr = (MIME_HEADER *) malloc(sizeof(MIME_HEADER)); | 825 | mhdr = (MIME_HEADER *) malloc(sizeof(MIME_HEADER)); |
826 | if (!mhdr) { | 826 | if (!mhdr) { |
827 | OPENSSL_free(tmpname); | 827 | OPENSSL_free(tmpname); |
828 | return NULL; | 828 | return NULL; |
829 | } | 829 | } |
830 | mhdr->name = tmpname; | 830 | mhdr->name = tmpname; |
831 | mhdr->value = tmpval; | 831 | mhdr->value = tmpval; |
832 | if (!(mhdr->params = sk_MIME_PARAM_new(mime_param_cmp))) { | 832 | if (!(mhdr->params = sk_MIME_PARAM_new(mime_param_cmp))) { |
833 | free(mhdr); | 833 | free(mhdr); |
834 | return NULL; | 834 | return NULL; |
835 | } | 835 | } |
836 | return mhdr; | 836 | return mhdr; |
837 | } | 837 | } |
838 | 838 | ||
@@ -849,13 +849,13 @@ static int mime_hdr_addparam(MIME_HEADER *mhdr, char *name, char *value) | |||
849 | if(isupper(c)) { | 849 | if(isupper(c)) { |
850 | c = tolower(c); | 850 | c = tolower(c); |
851 | *p = c; | 851 | *p = c; |
852 | } | ||
853 | } | 852 | } |
854 | } else tmpname = NULL; | 853 | } |
854 | } else tmpname = NULL; | ||
855 | if(value) { | 855 | if(value) { |
856 | tmpval = BUF_strdup(value); | 856 | tmpval = BUF_strdup(value); |
857 | if(!tmpval) return 0; | 857 | if(!tmpval) return 0; |
858 | } else tmpval = NULL; | 858 | } else tmpval = NULL; |
859 | /* Parameter values are case sensitive so leave as is */ | 859 | /* Parameter values are case sensitive so leave as is */ |
860 | mparam = (MIME_PARAM *) malloc(sizeof(MIME_PARAM)); | 860 | mparam = (MIME_PARAM *) malloc(sizeof(MIME_PARAM)); |
861 | if(!mparam) return 0; | 861 | if(!mparam) return 0; |
@@ -934,24 +934,24 @@ static int mime_bound_check(char *line, int linelen, char *bound, int blen) | |||
934 | if(!strncmp(line, "--", 2) && !strncmp(line + 2, bound, blen)) { | 934 | if(!strncmp(line, "--", 2) && !strncmp(line + 2, bound, blen)) { |
935 | if(!strncmp(line + blen + 2, "--", 2)) return 2; | 935 | if(!strncmp(line + blen + 2, "--", 2)) return 2; |
936 | else return 1; | 936 | else return 1; |
937 | } | 937 | } |
938 | return 0; | 938 | return 0; |
939 | } | 939 | } |
940 | 940 | ||
941 | static int strip_eol(char *linebuf, int *plen) | 941 | static int strip_eol(char *linebuf, int *plen) |
942 | { | 942 | { |
943 | int len = *plen; | 943 | int len = *plen; |
944 | char *p, c; | 944 | char *p, c; |
945 | int is_eol = 0; | 945 | int is_eol = 0; |
946 | p = linebuf + len - 1; | 946 | p = linebuf + len - 1; |
947 | for (p = linebuf + len - 1; len > 0; len--, p--) | 947 | for (p = linebuf + len - 1; len > 0; len--, p--) |
948 | { | 948 | { |
949 | c = *p; | 949 | c = *p; |
950 | if (c == '\n') | 950 | if (c == '\n') |
951 | is_eol = 1; | 951 | is_eol = 1; |
952 | else if (c != '\r') | 952 | else if (c != '\r') |
953 | break; | 953 | break; |
954 | } | 954 | } |
955 | *plen = len; | 955 | *plen = len; |
956 | return is_eol; | 956 | return is_eol; |
957 | } | 957 | } |
diff --git a/src/lib/libcrypto/asn1/asn_moid.c b/src/lib/libcrypto/asn1/asn_moid.c index fd04d11459..7521496d67 100644 --- a/src/lib/libcrypto/asn1/asn_moid.c +++ b/src/lib/libcrypto/asn1/asn_moid.c | |||
@@ -69,38 +69,38 @@ | |||
69 | static int do_create(char *value, char *name); | 69 | static int do_create(char *value, char *name); |
70 | 70 | ||
71 | static int oid_module_init(CONF_IMODULE *md, const CONF *cnf) | 71 | static int oid_module_init(CONF_IMODULE *md, const CONF *cnf) |
72 | { | 72 | { |
73 | int i; | 73 | int i; |
74 | const char *oid_section; | 74 | const char *oid_section; |
75 | STACK_OF(CONF_VALUE) *sktmp; | 75 | STACK_OF(CONF_VALUE) *sktmp; |
76 | CONF_VALUE *oval; | 76 | CONF_VALUE *oval; |
77 | oid_section = CONF_imodule_get_value(md); | 77 | oid_section = CONF_imodule_get_value(md); |
78 | if(!(sktmp = NCONF_get_section(cnf, oid_section))) | 78 | if(!(sktmp = NCONF_get_section(cnf, oid_section))) |
79 | { | 79 | { |
80 | ASN1err(ASN1_F_OID_MODULE_INIT, ASN1_R_ERROR_LOADING_SECTION); | 80 | ASN1err(ASN1_F_OID_MODULE_INIT, ASN1_R_ERROR_LOADING_SECTION); |
81 | return 0; | 81 | return 0; |
82 | } | 82 | } |
83 | for(i = 0; i < sk_CONF_VALUE_num(sktmp); i++) | 83 | for(i = 0; i < sk_CONF_VALUE_num(sktmp); i++) |
84 | { | 84 | { |
85 | oval = sk_CONF_VALUE_value(sktmp, i); | 85 | oval = sk_CONF_VALUE_value(sktmp, i); |
86 | if(!do_create(oval->value, oval->name)) | 86 | if(!do_create(oval->value, oval->name)) |
87 | { | 87 | { |
88 | ASN1err(ASN1_F_OID_MODULE_INIT, ASN1_R_ADDING_OBJECT); | 88 | ASN1err(ASN1_F_OID_MODULE_INIT, ASN1_R_ADDING_OBJECT); |
89 | return 0; | 89 | return 0; |
90 | } | ||
91 | } | 90 | } |
92 | return 1; | ||
93 | } | 91 | } |
92 | return 1; | ||
93 | } | ||
94 | 94 | ||
95 | static void oid_module_finish(CONF_IMODULE *md) | 95 | static void oid_module_finish(CONF_IMODULE *md) |
96 | { | 96 | { |
97 | OBJ_cleanup(); | 97 | OBJ_cleanup(); |
98 | } | 98 | } |
99 | 99 | ||
100 | void ASN1_add_oid_module(void) | 100 | void ASN1_add_oid_module(void) |
101 | { | 101 | { |
102 | CONF_module_add("oid_section", oid_module_init, oid_module_finish); | 102 | CONF_module_add("oid_section", oid_module_init, oid_module_finish); |
103 | } | 103 | } |
104 | 104 | ||
105 | /* Create an OID based on a name value pair. Accept two formats. | 105 | /* Create an OID based on a name value pair. Accept two formats. |
106 | * shortname = 1.2.3.4 | 106 | * shortname = 1.2.3.4 |
@@ -109,24 +109,24 @@ void ASN1_add_oid_module(void) | |||
109 | 109 | ||
110 | 110 | ||
111 | static int do_create(char *value, char *name) | 111 | static int do_create(char *value, char *name) |
112 | { | 112 | { |
113 | int nid; | 113 | int nid; |
114 | ASN1_OBJECT *oid; | 114 | ASN1_OBJECT *oid; |
115 | char *ln, *ostr, *p, *lntmp; | 115 | char *ln, *ostr, *p, *lntmp; |
116 | p = strrchr(value, ','); | 116 | p = strrchr(value, ','); |
117 | if (!p) | 117 | if (!p) |
118 | { | 118 | { |
119 | ln = name; | 119 | ln = name; |
120 | ostr = value; | 120 | ostr = value; |
121 | } | 121 | } |
122 | else | 122 | else |
123 | { | 123 | { |
124 | ln = NULL; | 124 | ln = NULL; |
125 | ostr = p + 1; | 125 | ostr = p + 1; |
126 | if (!*ostr) | 126 | if (!*ostr) |
127 | return 0; | 127 | return 0; |
128 | while(isspace((unsigned char)*ostr)) ostr++; | 128 | while(isspace((unsigned char)*ostr)) ostr++; |
129 | } | 129 | } |
130 | 130 | ||
131 | nid = OBJ_create(ostr, name, ln); | 131 | nid = OBJ_create(ostr, name, ln); |
132 | 132 | ||
@@ -134,16 +134,16 @@ static int do_create(char *value, char *name) | |||
134 | return 0; | 134 | return 0; |
135 | 135 | ||
136 | if (p) | 136 | if (p) |
137 | { | 137 | { |
138 | ln = value; | 138 | ln = value; |
139 | while(isspace((unsigned char)*ln)) ln++; | 139 | while(isspace((unsigned char)*ln)) ln++; |
140 | p--; | 140 | p--; |
141 | while(isspace((unsigned char)*p)) | 141 | while(isspace((unsigned char)*p)) |
142 | { | 142 | { |
143 | if (p == ln) | 143 | if (p == ln) |
144 | return 0; | 144 | return 0; |
145 | p--; | 145 | p--; |
146 | } | 146 | } |
147 | p++; | 147 | p++; |
148 | lntmp = malloc((p - ln) + 1); | 148 | lntmp = malloc((p - ln) + 1); |
149 | if (lntmp == NULL) | 149 | if (lntmp == NULL) |
@@ -152,9 +152,9 @@ static int do_create(char *value, char *name) | |||
152 | lntmp[p - ln] = 0; | 152 | lntmp[p - ln] = 0; |
153 | oid = OBJ_nid2obj(nid); | 153 | oid = OBJ_nid2obj(nid); |
154 | oid->ln = lntmp; | 154 | oid->ln = lntmp; |
155 | } | 155 | } |
156 | 156 | ||
157 | return 1; | 157 | return 1; |
158 | } | 158 | } |
159 | 159 | ||
160 | 160 | ||
diff --git a/src/lib/libcrypto/asn1/bio_asn1.c b/src/lib/libcrypto/asn1/bio_asn1.c index b59645909c..a6ad850e46 100644 --- a/src/lib/libcrypto/asn1/bio_asn1.c +++ b/src/lib/libcrypto/asn1/bio_asn1.c | |||
@@ -69,7 +69,7 @@ | |||
69 | #define DEFAULT_ASN1_BUF_SIZE 20 | 69 | #define DEFAULT_ASN1_BUF_SIZE 20 |
70 | 70 | ||
71 | typedef enum | 71 | typedef enum |
72 | { | 72 | { |
73 | ASN1_STATE_START, | 73 | ASN1_STATE_START, |
74 | ASN1_STATE_PRE_COPY, | 74 | ASN1_STATE_PRE_COPY, |
75 | ASN1_STATE_HEADER, | 75 | ASN1_STATE_HEADER, |
@@ -77,16 +77,16 @@ typedef enum | |||
77 | ASN1_STATE_DATA_COPY, | 77 | ASN1_STATE_DATA_COPY, |
78 | ASN1_STATE_POST_COPY, | 78 | ASN1_STATE_POST_COPY, |
79 | ASN1_STATE_DONE | 79 | ASN1_STATE_DONE |
80 | } asn1_bio_state_t; | 80 | } asn1_bio_state_t; |
81 | 81 | ||
82 | typedef struct BIO_ASN1_EX_FUNCS_st | 82 | typedef struct BIO_ASN1_EX_FUNCS_st |
83 | { | 83 | { |
84 | asn1_ps_func *ex_func; | 84 | asn1_ps_func *ex_func; |
85 | asn1_ps_func *ex_free_func; | 85 | asn1_ps_func *ex_free_func; |
86 | } BIO_ASN1_EX_FUNCS; | 86 | } BIO_ASN1_EX_FUNCS; |
87 | 87 | ||
88 | typedef struct BIO_ASN1_BUF_CTX_t | 88 | typedef struct BIO_ASN1_BUF_CTX_t |
89 | { | 89 | { |
90 | /* Internal state */ | 90 | /* Internal state */ |
91 | asn1_bio_state_t state; | 91 | asn1_bio_state_t state; |
92 | /* Internal buffer */ | 92 | /* Internal buffer */ |
@@ -107,7 +107,7 @@ typedef struct BIO_ASN1_BUF_CTX_t | |||
107 | int ex_len; | 107 | int ex_len; |
108 | int ex_pos; | 108 | int ex_pos; |
109 | void *ex_arg; | 109 | void *ex_arg; |
110 | } BIO_ASN1_BUF_CTX; | 110 | } BIO_ASN1_BUF_CTX; |
111 | 111 | ||
112 | 112 | ||
113 | static int asn1_bio_write(BIO *h, const char *buf,int num); | 113 | static int asn1_bio_write(BIO *h, const char *buf,int num); |
@@ -128,7 +128,7 @@ static int asn1_bio_setup_ex(BIO *b, BIO_ASN1_BUF_CTX *ctx, | |||
128 | asn1_bio_state_t other_state); | 128 | asn1_bio_state_t other_state); |
129 | 129 | ||
130 | static BIO_METHOD methods_asn1= | 130 | static BIO_METHOD methods_asn1= |
131 | { | 131 | { |
132 | BIO_TYPE_ASN1, | 132 | BIO_TYPE_ASN1, |
133 | "asn1", | 133 | "asn1", |
134 | asn1_bio_write, | 134 | asn1_bio_write, |
@@ -139,16 +139,16 @@ static BIO_METHOD methods_asn1= | |||
139 | asn1_bio_new, | 139 | asn1_bio_new, |
140 | asn1_bio_free, | 140 | asn1_bio_free, |
141 | asn1_bio_callback_ctrl, | 141 | asn1_bio_callback_ctrl, |
142 | }; | 142 | }; |
143 | 143 | ||
144 | BIO_METHOD *BIO_f_asn1(void) | 144 | BIO_METHOD *BIO_f_asn1(void) |
145 | { | 145 | { |
146 | return(&methods_asn1); | 146 | return(&methods_asn1); |
147 | } | 147 | } |
148 | 148 | ||
149 | 149 | ||
150 | static int asn1_bio_new(BIO *b) | 150 | static int asn1_bio_new(BIO *b) |
151 | { | 151 | { |
152 | BIO_ASN1_BUF_CTX *ctx; | 152 | BIO_ASN1_BUF_CTX *ctx; |
153 | ctx = malloc(sizeof(BIO_ASN1_BUF_CTX)); | 153 | ctx = malloc(sizeof(BIO_ASN1_BUF_CTX)); |
154 | if (!ctx) | 154 | if (!ctx) |
@@ -156,15 +156,15 @@ static int asn1_bio_new(BIO *b) | |||
156 | if (!asn1_bio_init(ctx, DEFAULT_ASN1_BUF_SIZE)) { | 156 | if (!asn1_bio_init(ctx, DEFAULT_ASN1_BUF_SIZE)) { |
157 | free(ctx); | 157 | free(ctx); |
158 | return 0; | 158 | return 0; |
159 | } | 159 | } |
160 | b->init = 1; | 160 | b->init = 1; |
161 | b->ptr = (char *)ctx; | 161 | b->ptr = (char *)ctx; |
162 | b->flags = 0; | 162 | b->flags = 0; |
163 | return 1; | 163 | return 1; |
164 | } | 164 | } |
165 | 165 | ||
166 | static int asn1_bio_init(BIO_ASN1_BUF_CTX *ctx, int size) | 166 | static int asn1_bio_init(BIO_ASN1_BUF_CTX *ctx, int size) |
167 | { | 167 | { |
168 | ctx->buf = malloc(size); | 168 | ctx->buf = malloc(size); |
169 | if (!ctx->buf) | 169 | if (!ctx->buf) |
170 | return 0; | 170 | return 0; |
@@ -179,10 +179,10 @@ static int asn1_bio_init(BIO_ASN1_BUF_CTX *ctx, int size) | |||
179 | ctx->ex_len = 0; | 179 | ctx->ex_len = 0; |
180 | ctx->state = ASN1_STATE_START; | 180 | ctx->state = ASN1_STATE_START; |
181 | return 1; | 181 | return 1; |
182 | } | 182 | } |
183 | 183 | ||
184 | static int asn1_bio_free(BIO *b) | 184 | static int asn1_bio_free(BIO *b) |
185 | { | 185 | { |
186 | BIO_ASN1_BUF_CTX *ctx; | 186 | BIO_ASN1_BUF_CTX *ctx; |
187 | ctx = (BIO_ASN1_BUF_CTX *) b->ptr; | 187 | ctx = (BIO_ASN1_BUF_CTX *) b->ptr; |
188 | if (ctx == NULL) | 188 | if (ctx == NULL) |
@@ -194,10 +194,10 @@ static int asn1_bio_free(BIO *b) | |||
194 | b->ptr = NULL; | 194 | b->ptr = NULL; |
195 | b->flags = 0; | 195 | b->flags = 0; |
196 | return 1; | 196 | return 1; |
197 | } | 197 | } |
198 | 198 | ||
199 | static int asn1_bio_write(BIO *b, const char *in , int inl) | 199 | static int asn1_bio_write(BIO *b, const char *in , int inl) |
200 | { | 200 | { |
201 | BIO_ASN1_BUF_CTX *ctx; | 201 | BIO_ASN1_BUF_CTX *ctx; |
202 | int wrmax, wrlen, ret; | 202 | int wrmax, wrlen, ret; |
203 | unsigned char *p; | 203 | unsigned char *p; |
@@ -211,9 +211,9 @@ static int asn1_bio_write(BIO *b, const char *in , int inl) | |||
211 | ret = -1; | 211 | ret = -1; |
212 | 212 | ||
213 | for(;;) | 213 | for(;;) |
214 | { | 214 | { |
215 | switch (ctx->state) | 215 | switch (ctx->state) |
216 | { | 216 | { |
217 | 217 | ||
218 | /* Setup prefix data, call it */ | 218 | /* Setup prefix data, call it */ |
219 | case ASN1_STATE_START: | 219 | case ASN1_STATE_START: |
@@ -255,10 +255,10 @@ static int asn1_bio_write(BIO *b, const char *in , int inl) | |||
255 | if (ctx->buflen) | 255 | if (ctx->buflen) |
256 | ctx->bufpos += ret; | 256 | ctx->bufpos += ret; |
257 | else | 257 | else |
258 | { | 258 | { |
259 | ctx->bufpos = 0; | 259 | ctx->bufpos = 0; |
260 | ctx->state = ASN1_STATE_DATA_COPY; | 260 | ctx->state = ASN1_STATE_DATA_COPY; |
261 | } | 261 | } |
262 | 262 | ||
263 | break; | 263 | break; |
264 | 264 | ||
@@ -288,26 +288,26 @@ static int asn1_bio_write(BIO *b, const char *in , int inl) | |||
288 | BIO_clear_retry_flags(b); | 288 | BIO_clear_retry_flags(b); |
289 | return 0; | 289 | return 0; |
290 | 290 | ||
291 | } | ||
292 | |||
293 | } | 291 | } |
294 | 292 | ||
293 | } | ||
294 | |||
295 | done: | 295 | done: |
296 | BIO_clear_retry_flags(b); | 296 | BIO_clear_retry_flags(b); |
297 | BIO_copy_next_retry(b); | 297 | BIO_copy_next_retry(b); |
298 | 298 | ||
299 | return (wrlen > 0) ? wrlen : ret; | 299 | return (wrlen > 0) ? wrlen : ret; |
300 | 300 | ||
301 | } | 301 | } |
302 | 302 | ||
303 | static int asn1_bio_flush_ex(BIO *b, BIO_ASN1_BUF_CTX *ctx, | 303 | static int asn1_bio_flush_ex(BIO *b, BIO_ASN1_BUF_CTX *ctx, |
304 | asn1_ps_func *cleanup, asn1_bio_state_t next) | 304 | asn1_ps_func *cleanup, asn1_bio_state_t next) |
305 | { | 305 | { |
306 | int ret; | 306 | int ret; |
307 | if (ctx->ex_len <= 0) | 307 | if (ctx->ex_len <= 0) |
308 | return 1; | 308 | return 1; |
309 | for(;;) | 309 | for(;;) |
310 | { | 310 | { |
311 | ret = BIO_write(b->next_bio, ctx->ex_buf + ctx->ex_pos, | 311 | ret = BIO_write(b->next_bio, ctx->ex_buf + ctx->ex_pos, |
312 | ctx->ex_len); | 312 | ctx->ex_len); |
313 | if (ret <= 0) | 313 | if (ret <= 0) |
@@ -316,62 +316,62 @@ static int asn1_bio_flush_ex(BIO *b, BIO_ASN1_BUF_CTX *ctx, | |||
316 | if (ctx->ex_len > 0) | 316 | if (ctx->ex_len > 0) |
317 | ctx->ex_pos += ret; | 317 | ctx->ex_pos += ret; |
318 | else | 318 | else |
319 | { | 319 | { |
320 | if(cleanup) | 320 | if(cleanup) |
321 | cleanup(b, &ctx->ex_buf, &ctx->ex_len, | 321 | cleanup(b, &ctx->ex_buf, &ctx->ex_len, |
322 | &ctx->ex_arg); | 322 | &ctx->ex_arg); |
323 | ctx->state = next; | 323 | ctx->state = next; |
324 | ctx->ex_pos = 0; | 324 | ctx->ex_pos = 0; |
325 | break; | 325 | break; |
326 | } | ||
327 | } | 326 | } |
328 | return ret; | ||
329 | } | 327 | } |
328 | return ret; | ||
329 | } | ||
330 | 330 | ||
331 | static int asn1_bio_setup_ex(BIO *b, BIO_ASN1_BUF_CTX *ctx, | 331 | static int asn1_bio_setup_ex(BIO *b, BIO_ASN1_BUF_CTX *ctx, |
332 | asn1_ps_func *setup, | 332 | asn1_ps_func *setup, |
333 | asn1_bio_state_t ex_state, | 333 | asn1_bio_state_t ex_state, |
334 | asn1_bio_state_t other_state) | 334 | asn1_bio_state_t other_state) |
335 | { | 335 | { |
336 | if (setup && !setup(b, &ctx->ex_buf, &ctx->ex_len, &ctx->ex_arg)) | 336 | if (setup && !setup(b, &ctx->ex_buf, &ctx->ex_len, &ctx->ex_arg)) |
337 | { | 337 | { |
338 | BIO_clear_retry_flags(b); | 338 | BIO_clear_retry_flags(b); |
339 | return 0; | 339 | return 0; |
340 | } | 340 | } |
341 | if (ctx->ex_len > 0) | 341 | if (ctx->ex_len > 0) |
342 | ctx->state = ex_state; | 342 | ctx->state = ex_state; |
343 | else | 343 | else |
344 | ctx->state = other_state; | 344 | ctx->state = other_state; |
345 | return 1; | 345 | return 1; |
346 | } | 346 | } |
347 | 347 | ||
348 | static int asn1_bio_read(BIO *b, char *in , int inl) | 348 | static int asn1_bio_read(BIO *b, char *in , int inl) |
349 | { | 349 | { |
350 | if (!b->next_bio) | 350 | if (!b->next_bio) |
351 | return 0; | 351 | return 0; |
352 | return BIO_read(b->next_bio, in , inl); | 352 | return BIO_read(b->next_bio, in , inl); |
353 | } | 353 | } |
354 | 354 | ||
355 | static int asn1_bio_puts(BIO *b, const char *str) | 355 | static int asn1_bio_puts(BIO *b, const char *str) |
356 | { | 356 | { |
357 | return asn1_bio_write(b, str, strlen(str)); | 357 | return asn1_bio_write(b, str, strlen(str)); |
358 | } | 358 | } |
359 | 359 | ||
360 | static int asn1_bio_gets(BIO *b, char *str, int size) | 360 | static int asn1_bio_gets(BIO *b, char *str, int size) |
361 | { | 361 | { |
362 | if (!b->next_bio) | 362 | if (!b->next_bio) |
363 | return 0; | 363 | return 0; |
364 | return BIO_gets(b->next_bio, str , size); | 364 | return BIO_gets(b->next_bio, str , size); |
365 | } | 365 | } |
366 | 366 | ||
367 | static long asn1_bio_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) | 367 | static long asn1_bio_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) |
368 | { | 368 | { |
369 | if (b->next_bio == NULL) return(0); | 369 | if (b->next_bio == NULL) return(0); |
370 | return BIO_callback_ctrl(b->next_bio,cmd,fp); | 370 | return BIO_callback_ctrl(b->next_bio,cmd,fp); |
371 | } | 371 | } |
372 | 372 | ||
373 | static long asn1_bio_ctrl(BIO *b, int cmd, long arg1, void *arg2) | 373 | static long asn1_bio_ctrl(BIO *b, int cmd, long arg1, void *arg2) |
374 | { | 374 | { |
375 | BIO_ASN1_BUF_CTX *ctx; | 375 | BIO_ASN1_BUF_CTX *ctx; |
376 | BIO_ASN1_EX_FUNCS *ex_func; | 376 | BIO_ASN1_EX_FUNCS *ex_func; |
377 | long ret = 1; | 377 | long ret = 1; |
@@ -379,7 +379,7 @@ static long asn1_bio_ctrl(BIO *b, int cmd, long arg1, void *arg2) | |||
379 | if (ctx == NULL) | 379 | if (ctx == NULL) |
380 | return 0; | 380 | return 0; |
381 | switch(cmd) | 381 | switch(cmd) |
382 | { | 382 | { |
383 | 383 | ||
384 | case BIO_C_SET_PREFIX: | 384 | case BIO_C_SET_PREFIX: |
385 | ex_func = arg2; | 385 | ex_func = arg2; |
@@ -419,27 +419,27 @@ static long asn1_bio_ctrl(BIO *b, int cmd, long arg1, void *arg2) | |||
419 | 419 | ||
420 | /* Call post function if possible */ | 420 | /* Call post function if possible */ |
421 | if (ctx->state == ASN1_STATE_HEADER) | 421 | if (ctx->state == ASN1_STATE_HEADER) |
422 | { | 422 | { |
423 | if (!asn1_bio_setup_ex(b, ctx, ctx->suffix, | 423 | if (!asn1_bio_setup_ex(b, ctx, ctx->suffix, |
424 | ASN1_STATE_POST_COPY, ASN1_STATE_DONE)) | 424 | ASN1_STATE_POST_COPY, ASN1_STATE_DONE)) |
425 | return 0; | 425 | return 0; |
426 | } | 426 | } |
427 | 427 | ||
428 | if (ctx->state == ASN1_STATE_POST_COPY) | 428 | if (ctx->state == ASN1_STATE_POST_COPY) |
429 | { | 429 | { |
430 | ret = asn1_bio_flush_ex(b, ctx, ctx->suffix_free, | 430 | ret = asn1_bio_flush_ex(b, ctx, ctx->suffix_free, |
431 | ASN1_STATE_DONE); | 431 | ASN1_STATE_DONE); |
432 | if (ret <= 0) | 432 | if (ret <= 0) |
433 | return ret; | 433 | return ret; |
434 | } | 434 | } |
435 | 435 | ||
436 | if (ctx->state == ASN1_STATE_DONE) | 436 | if (ctx->state == ASN1_STATE_DONE) |
437 | return BIO_ctrl(b->next_bio, cmd, arg1, arg2); | 437 | return BIO_ctrl(b->next_bio, cmd, arg1, arg2); |
438 | else | 438 | else |
439 | { | 439 | { |
440 | BIO_clear_retry_flags(b); | 440 | BIO_clear_retry_flags(b); |
441 | return 0; | 441 | return 0; |
442 | } | 442 | } |
443 | break; | 443 | break; |
444 | 444 | ||
445 | 445 | ||
@@ -448,50 +448,50 @@ static long asn1_bio_ctrl(BIO *b, int cmd, long arg1, void *arg2) | |||
448 | return 0; | 448 | return 0; |
449 | return BIO_ctrl(b->next_bio, cmd, arg1, arg2); | 449 | return BIO_ctrl(b->next_bio, cmd, arg1, arg2); |
450 | 450 | ||
451 | } | 451 | } |
452 | 452 | ||
453 | return ret; | 453 | return ret; |
454 | } | 454 | } |
455 | 455 | ||
456 | static int asn1_bio_set_ex(BIO *b, int cmd, | 456 | static int asn1_bio_set_ex(BIO *b, int cmd, |
457 | asn1_ps_func *ex_func, asn1_ps_func *ex_free_func) | 457 | asn1_ps_func *ex_func, asn1_ps_func *ex_free_func) |
458 | { | 458 | { |
459 | BIO_ASN1_EX_FUNCS extmp; | 459 | BIO_ASN1_EX_FUNCS extmp; |
460 | extmp.ex_func = ex_func; | 460 | extmp.ex_func = ex_func; |
461 | extmp.ex_free_func = ex_free_func; | 461 | extmp.ex_free_func = ex_free_func; |
462 | return BIO_ctrl(b, cmd, 0, &extmp); | 462 | return BIO_ctrl(b, cmd, 0, &extmp); |
463 | } | 463 | } |
464 | 464 | ||
465 | static int asn1_bio_get_ex(BIO *b, int cmd, | 465 | static int asn1_bio_get_ex(BIO *b, int cmd, |
466 | asn1_ps_func **ex_func, asn1_ps_func **ex_free_func) | 466 | asn1_ps_func **ex_func, asn1_ps_func **ex_free_func) |
467 | { | 467 | { |
468 | BIO_ASN1_EX_FUNCS extmp; | 468 | BIO_ASN1_EX_FUNCS extmp; |
469 | int ret; | 469 | int ret; |
470 | ret = BIO_ctrl(b, cmd, 0, &extmp); | 470 | ret = BIO_ctrl(b, cmd, 0, &extmp); |
471 | if (ret > 0) | 471 | if (ret > 0) |
472 | { | 472 | { |
473 | *ex_func = extmp.ex_func; | 473 | *ex_func = extmp.ex_func; |
474 | *ex_free_func = extmp.ex_free_func; | 474 | *ex_free_func = extmp.ex_free_func; |
475 | } | ||
476 | return ret; | ||
477 | } | 475 | } |
476 | return ret; | ||
477 | } | ||
478 | 478 | ||
479 | int BIO_asn1_set_prefix(BIO *b, asn1_ps_func *prefix, asn1_ps_func *prefix_free) | 479 | int BIO_asn1_set_prefix(BIO *b, asn1_ps_func *prefix, asn1_ps_func *prefix_free) |
480 | { | 480 | { |
481 | return asn1_bio_set_ex(b, BIO_C_SET_PREFIX, prefix, prefix_free); | 481 | return asn1_bio_set_ex(b, BIO_C_SET_PREFIX, prefix, prefix_free); |
482 | } | 482 | } |
483 | 483 | ||
484 | int BIO_asn1_get_prefix(BIO *b, asn1_ps_func **pprefix, asn1_ps_func **pprefix_free) | 484 | int BIO_asn1_get_prefix(BIO *b, asn1_ps_func **pprefix, asn1_ps_func **pprefix_free) |
485 | { | 485 | { |
486 | return asn1_bio_get_ex(b, BIO_C_GET_PREFIX, pprefix, pprefix_free); | 486 | return asn1_bio_get_ex(b, BIO_C_GET_PREFIX, pprefix, pprefix_free); |
487 | } | 487 | } |
488 | 488 | ||
489 | int BIO_asn1_set_suffix(BIO *b, asn1_ps_func *suffix, asn1_ps_func *suffix_free) | 489 | int BIO_asn1_set_suffix(BIO *b, asn1_ps_func *suffix, asn1_ps_func *suffix_free) |
490 | { | 490 | { |
491 | return asn1_bio_set_ex(b, BIO_C_SET_SUFFIX, suffix, suffix_free); | 491 | return asn1_bio_set_ex(b, BIO_C_SET_SUFFIX, suffix, suffix_free); |
492 | } | 492 | } |
493 | 493 | ||
494 | int BIO_asn1_get_suffix(BIO *b, asn1_ps_func **psuffix, asn1_ps_func **psuffix_free) | 494 | int BIO_asn1_get_suffix(BIO *b, asn1_ps_func **psuffix, asn1_ps_func **psuffix_free) |
495 | { | 495 | { |
496 | return asn1_bio_get_ex(b, BIO_C_GET_SUFFIX, psuffix, psuffix_free); | 496 | return asn1_bio_get_ex(b, BIO_C_GET_SUFFIX, psuffix, psuffix_free); |
497 | } | 497 | } |
diff --git a/src/lib/libcrypto/asn1/bio_ndef.c b/src/lib/libcrypto/asn1/bio_ndef.c index 60f324bdae..b8dc80a7b2 100644 --- a/src/lib/libcrypto/asn1/bio_ndef.c +++ b/src/lib/libcrypto/asn1/bio_ndef.c | |||
@@ -79,7 +79,7 @@ | |||
79 | /* BIO support data stored in the ASN1 BIO ex_arg */ | 79 | /* BIO support data stored in the ASN1 BIO ex_arg */ |
80 | 80 | ||
81 | typedef struct ndef_aux_st | 81 | typedef struct ndef_aux_st |
82 | { | 82 | { |
83 | /* ASN1 structure this BIO refers to */ | 83 | /* ASN1 structure this BIO refers to */ |
84 | ASN1_VALUE *val; | 84 | ASN1_VALUE *val; |
85 | const ASN1_ITEM *it; | 85 | const ASN1_ITEM *it; |
@@ -91,7 +91,7 @@ typedef struct ndef_aux_st | |||
91 | unsigned char **boundary; | 91 | unsigned char **boundary; |
92 | /* DER buffer start */ | 92 | /* DER buffer start */ |
93 | unsigned char *derbuf; | 93 | unsigned char *derbuf; |
94 | } NDEF_SUPPORT; | 94 | } NDEF_SUPPORT; |
95 | 95 | ||
96 | static int ndef_prefix(BIO *b, unsigned char **pbuf, int *plen, void *parg); | 96 | static int ndef_prefix(BIO *b, unsigned char **pbuf, int *plen, void *parg); |
97 | static int ndef_prefix_free(BIO *b, unsigned char **pbuf, int *plen, void *parg); | 97 | static int ndef_prefix_free(BIO *b, unsigned char **pbuf, int *plen, void *parg); |
@@ -99,17 +99,17 @@ static int ndef_suffix(BIO *b, unsigned char **pbuf, int *plen, void *parg); | |||
99 | static int ndef_suffix_free(BIO *b, unsigned char **pbuf, int *plen, void *parg); | 99 | static int ndef_suffix_free(BIO *b, unsigned char **pbuf, int *plen, void *parg); |
100 | 100 | ||
101 | BIO *BIO_new_NDEF(BIO *out, ASN1_VALUE *val, const ASN1_ITEM *it) | 101 | BIO *BIO_new_NDEF(BIO *out, ASN1_VALUE *val, const ASN1_ITEM *it) |
102 | { | 102 | { |
103 | NDEF_SUPPORT *ndef_aux = NULL; | 103 | NDEF_SUPPORT *ndef_aux = NULL; |
104 | BIO *asn_bio = NULL; | 104 | BIO *asn_bio = NULL; |
105 | const ASN1_AUX *aux = it->funcs; | 105 | const ASN1_AUX *aux = it->funcs; |
106 | ASN1_STREAM_ARG sarg; | 106 | ASN1_STREAM_ARG sarg; |
107 | 107 | ||
108 | if (!aux || !aux->asn1_cb) | 108 | if (!aux || !aux->asn1_cb) |
109 | { | 109 | { |
110 | ASN1err(ASN1_F_BIO_NEW_NDEF, ASN1_R_STREAMING_NOT_SUPPORTED); | 110 | ASN1err(ASN1_F_BIO_NEW_NDEF, ASN1_R_STREAMING_NOT_SUPPORTED); |
111 | return NULL; | 111 | return NULL; |
112 | } | 112 | } |
113 | ndef_aux = malloc(sizeof(NDEF_SUPPORT)); | 113 | ndef_aux = malloc(sizeof(NDEF_SUPPORT)); |
114 | asn_bio = BIO_new(BIO_f_asn1()); | 114 | asn_bio = BIO_new(BIO_f_asn1()); |
115 | 115 | ||
@@ -150,10 +150,10 @@ BIO *BIO_new_NDEF(BIO *out, ASN1_VALUE *val, const ASN1_ITEM *it) | |||
150 | if (ndef_aux) | 150 | if (ndef_aux) |
151 | free(ndef_aux); | 151 | free(ndef_aux); |
152 | return NULL; | 152 | return NULL; |
153 | } | 153 | } |
154 | 154 | ||
155 | static int ndef_prefix(BIO *b, unsigned char **pbuf, int *plen, void *parg) | 155 | static int ndef_prefix(BIO *b, unsigned char **pbuf, int *plen, void *parg) |
156 | { | 156 | { |
157 | NDEF_SUPPORT *ndef_aux; | 157 | NDEF_SUPPORT *ndef_aux; |
158 | unsigned char *p; | 158 | unsigned char *p; |
159 | int derlen; | 159 | int derlen; |
@@ -175,10 +175,10 @@ static int ndef_prefix(BIO *b, unsigned char **pbuf, int *plen, void *parg) | |||
175 | *plen = *ndef_aux->boundary - *pbuf; | 175 | *plen = *ndef_aux->boundary - *pbuf; |
176 | 176 | ||
177 | return 1; | 177 | return 1; |
178 | } | 178 | } |
179 | 179 | ||
180 | static int ndef_prefix_free(BIO *b, unsigned char **pbuf, int *plen, void *parg) | 180 | static int ndef_prefix_free(BIO *b, unsigned char **pbuf, int *plen, void *parg) |
181 | { | 181 | { |
182 | NDEF_SUPPORT *ndef_aux; | 182 | NDEF_SUPPORT *ndef_aux; |
183 | 183 | ||
184 | if (!parg) | 184 | if (!parg) |
@@ -193,20 +193,20 @@ static int ndef_prefix_free(BIO *b, unsigned char **pbuf, int *plen, void *parg) | |||
193 | *pbuf = NULL; | 193 | *pbuf = NULL; |
194 | *plen = 0; | 194 | *plen = 0; |
195 | return 1; | 195 | return 1; |
196 | } | 196 | } |
197 | 197 | ||
198 | static int ndef_suffix_free(BIO *b, unsigned char **pbuf, int *plen, void *parg) | 198 | static int ndef_suffix_free(BIO *b, unsigned char **pbuf, int *plen, void *parg) |
199 | { | 199 | { |
200 | NDEF_SUPPORT **pndef_aux = (NDEF_SUPPORT **)parg; | 200 | NDEF_SUPPORT **pndef_aux = (NDEF_SUPPORT **)parg; |
201 | if (!ndef_prefix_free(b, pbuf, plen, parg)) | 201 | if (!ndef_prefix_free(b, pbuf, plen, parg)) |
202 | return 0; | 202 | return 0; |
203 | free(*pndef_aux); | 203 | free(*pndef_aux); |
204 | *pndef_aux = NULL; | 204 | *pndef_aux = NULL; |
205 | return 1; | 205 | return 1; |
206 | } | 206 | } |
207 | 207 | ||
208 | static int ndef_suffix(BIO *b, unsigned char **pbuf, int *plen, void *parg) | 208 | static int ndef_suffix(BIO *b, unsigned char **pbuf, int *plen, void *parg) |
209 | { | 209 | { |
210 | NDEF_SUPPORT *ndef_aux; | 210 | NDEF_SUPPORT *ndef_aux; |
211 | unsigned char *p; | 211 | unsigned char *p; |
212 | int derlen; | 212 | int derlen; |
@@ -240,4 +240,4 @@ static int ndef_suffix(BIO *b, unsigned char **pbuf, int *plen, void *parg) | |||
240 | *plen = derlen - (*ndef_aux->boundary - ndef_aux->derbuf); | 240 | *plen = derlen - (*ndef_aux->boundary - ndef_aux->derbuf); |
241 | 241 | ||
242 | return 1; | 242 | return 1; |
243 | } | 243 | } |
diff --git a/src/lib/libcrypto/asn1/d2i_pr.c b/src/lib/libcrypto/asn1/d2i_pr.c index 2828944777..cbbcdae7df 100644 --- a/src/lib/libcrypto/asn1/d2i_pr.c +++ b/src/lib/libcrypto/asn1/d2i_pr.c | |||
@@ -70,40 +70,40 @@ | |||
70 | 70 | ||
71 | EVP_PKEY *d2i_PrivateKey(int type, EVP_PKEY **a, const unsigned char **pp, | 71 | EVP_PKEY *d2i_PrivateKey(int type, EVP_PKEY **a, const unsigned char **pp, |
72 | long length) | 72 | long length) |
73 | { | 73 | { |
74 | EVP_PKEY *ret; | 74 | EVP_PKEY *ret; |
75 | 75 | ||
76 | if ((a == NULL) || (*a == NULL)) | 76 | if ((a == NULL) || (*a == NULL)) |
77 | { | 77 | { |
78 | if ((ret=EVP_PKEY_new()) == NULL) | 78 | if ((ret=EVP_PKEY_new()) == NULL) |
79 | { | 79 | { |
80 | ASN1err(ASN1_F_D2I_PRIVATEKEY,ERR_R_EVP_LIB); | 80 | ASN1err(ASN1_F_D2I_PRIVATEKEY,ERR_R_EVP_LIB); |
81 | return(NULL); | 81 | return(NULL); |
82 | } | ||
83 | } | 82 | } |
83 | } | ||
84 | else | 84 | else |
85 | { | 85 | { |
86 | ret= *a; | 86 | ret= *a; |
87 | #ifndef OPENSSL_NO_ENGINE | 87 | #ifndef OPENSSL_NO_ENGINE |
88 | if (ret->engine) | 88 | if (ret->engine) |
89 | { | 89 | { |
90 | ENGINE_finish(ret->engine); | 90 | ENGINE_finish(ret->engine); |
91 | ret->engine = NULL; | 91 | ret->engine = NULL; |
92 | } | ||
93 | #endif | ||
94 | } | 92 | } |
93 | #endif | ||
94 | } | ||
95 | 95 | ||
96 | if (!EVP_PKEY_set_type(ret, type)) | 96 | if (!EVP_PKEY_set_type(ret, type)) |
97 | { | 97 | { |
98 | ASN1err(ASN1_F_D2I_PRIVATEKEY,ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE); | 98 | ASN1err(ASN1_F_D2I_PRIVATEKEY,ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE); |
99 | goto err; | 99 | goto err; |
100 | } | 100 | } |
101 | 101 | ||
102 | if (!ret->ameth->old_priv_decode || | 102 | if (!ret->ameth->old_priv_decode || |
103 | !ret->ameth->old_priv_decode(ret, pp, length)) | 103 | !ret->ameth->old_priv_decode(ret, pp, length)) |
104 | { | 104 | { |
105 | if (ret->ameth->priv_decode) | 105 | if (ret->ameth->priv_decode) |
106 | { | 106 | { |
107 | PKCS8_PRIV_KEY_INFO *p8=NULL; | 107 | PKCS8_PRIV_KEY_INFO *p8=NULL; |
108 | p8=d2i_PKCS8_PRIV_KEY_INFO(NULL,pp,length); | 108 | p8=d2i_PKCS8_PRIV_KEY_INFO(NULL,pp,length); |
109 | if (!p8) goto err; | 109 | if (!p8) goto err; |
@@ -111,19 +111,19 @@ EVP_PKEY *d2i_PrivateKey(int type, EVP_PKEY **a, const unsigned char **pp, | |||
111 | ret = EVP_PKCS82PKEY(p8); | 111 | ret = EVP_PKCS82PKEY(p8); |
112 | PKCS8_PRIV_KEY_INFO_free(p8); | 112 | PKCS8_PRIV_KEY_INFO_free(p8); |
113 | 113 | ||
114 | } | 114 | } |
115 | else | 115 | else |
116 | { | 116 | { |
117 | ASN1err(ASN1_F_D2I_PRIVATEKEY,ERR_R_ASN1_LIB); | 117 | ASN1err(ASN1_F_D2I_PRIVATEKEY,ERR_R_ASN1_LIB); |
118 | goto err; | 118 | goto err; |
119 | } | 119 | } |
120 | } | 120 | } |
121 | if (a != NULL) (*a)=ret; | 121 | if (a != NULL) (*a)=ret; |
122 | return(ret); | 122 | return(ret); |
123 | err: | 123 | err: |
124 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) EVP_PKEY_free(ret); | 124 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) EVP_PKEY_free(ret); |
125 | return(NULL); | 125 | return(NULL); |
126 | } | 126 | } |
127 | 127 | ||
128 | /* This works like d2i_PrivateKey() except it automatically works out the type */ | 128 | /* This works like d2i_PrivateKey() except it automatically works out the type */ |
129 | 129 | ||
@@ -147,23 +147,23 @@ EVP_PKEY *d2i_AutoPrivateKey(EVP_PKEY **a, const unsigned char **pp, | |||
147 | else if (sk_ASN1_TYPE_num(inkey) == 4) | 147 | else if (sk_ASN1_TYPE_num(inkey) == 4) |
148 | keytype = EVP_PKEY_EC; | 148 | keytype = EVP_PKEY_EC; |
149 | else if (sk_ASN1_TYPE_num(inkey) == 3) | 149 | else if (sk_ASN1_TYPE_num(inkey) == 3) |
150 | { /* This seems to be PKCS8, not traditional format */ | 150 | { /* This seems to be PKCS8, not traditional format */ |
151 | PKCS8_PRIV_KEY_INFO *p8 = d2i_PKCS8_PRIV_KEY_INFO(NULL,pp,length); | 151 | PKCS8_PRIV_KEY_INFO *p8 = d2i_PKCS8_PRIV_KEY_INFO(NULL,pp,length); |
152 | EVP_PKEY *ret; | 152 | EVP_PKEY *ret; |
153 | 153 | ||
154 | sk_ASN1_TYPE_pop_free(inkey, ASN1_TYPE_free); | 154 | sk_ASN1_TYPE_pop_free(inkey, ASN1_TYPE_free); |
155 | if (!p8) | 155 | if (!p8) |
156 | { | 156 | { |
157 | ASN1err(ASN1_F_D2I_AUTOPRIVATEKEY,ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE); | 157 | ASN1err(ASN1_F_D2I_AUTOPRIVATEKEY,ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE); |
158 | return NULL; | 158 | return NULL; |
159 | } | 159 | } |
160 | ret = EVP_PKCS82PKEY(p8); | 160 | ret = EVP_PKCS82PKEY(p8); |
161 | PKCS8_PRIV_KEY_INFO_free(p8); | 161 | PKCS8_PRIV_KEY_INFO_free(p8); |
162 | if (a) { | 162 | if (a) { |
163 | *a = ret; | 163 | *a = ret; |
164 | } | 164 | } |
165 | return ret; | 165 | return ret; |
166 | } | 166 | } |
167 | else keytype = EVP_PKEY_RSA; | 167 | else keytype = EVP_PKEY_RSA; |
168 | sk_ASN1_TYPE_pop_free(inkey, ASN1_TYPE_free); | 168 | sk_ASN1_TYPE_pop_free(inkey, ASN1_TYPE_free); |
169 | return d2i_PrivateKey(keytype, a, pp, length); | 169 | return d2i_PrivateKey(keytype, a, pp, length); |
diff --git a/src/lib/libcrypto/asn1/d2i_pu.c b/src/lib/libcrypto/asn1/d2i_pu.c index c8f39ceb03..f04d230d70 100644 --- a/src/lib/libcrypto/asn1/d2i_pu.c +++ b/src/lib/libcrypto/asn1/d2i_pu.c | |||
@@ -74,66 +74,66 @@ | |||
74 | 74 | ||
75 | EVP_PKEY *d2i_PublicKey(int type, EVP_PKEY **a, const unsigned char **pp, | 75 | EVP_PKEY *d2i_PublicKey(int type, EVP_PKEY **a, const unsigned char **pp, |
76 | long length) | 76 | long length) |
77 | { | 77 | { |
78 | EVP_PKEY *ret; | 78 | EVP_PKEY *ret; |
79 | 79 | ||
80 | if ((a == NULL) || (*a == NULL)) | 80 | if ((a == NULL) || (*a == NULL)) |
81 | { | 81 | { |
82 | if ((ret=EVP_PKEY_new()) == NULL) | 82 | if ((ret=EVP_PKEY_new()) == NULL) |
83 | { | 83 | { |
84 | ASN1err(ASN1_F_D2I_PUBLICKEY,ERR_R_EVP_LIB); | 84 | ASN1err(ASN1_F_D2I_PUBLICKEY,ERR_R_EVP_LIB); |
85 | return(NULL); | 85 | return(NULL); |
86 | } | ||
87 | } | 86 | } |
87 | } | ||
88 | else ret= *a; | 88 | else ret= *a; |
89 | 89 | ||
90 | if (!EVP_PKEY_set_type(ret, type)) | 90 | if (!EVP_PKEY_set_type(ret, type)) |
91 | { | 91 | { |
92 | ASN1err(ASN1_F_D2I_PUBLICKEY,ERR_R_EVP_LIB); | 92 | ASN1err(ASN1_F_D2I_PUBLICKEY,ERR_R_EVP_LIB); |
93 | goto err; | 93 | goto err; |
94 | } | 94 | } |
95 | 95 | ||
96 | switch (EVP_PKEY_id(ret)) | 96 | switch (EVP_PKEY_id(ret)) |
97 | { | 97 | { |
98 | #ifndef OPENSSL_NO_RSA | 98 | #ifndef OPENSSL_NO_RSA |
99 | case EVP_PKEY_RSA: | 99 | case EVP_PKEY_RSA: |
100 | if ((ret->pkey.rsa=d2i_RSAPublicKey(NULL, | 100 | if ((ret->pkey.rsa=d2i_RSAPublicKey(NULL, |
101 | (const unsigned char **)pp,length)) == NULL) /* TMP UGLY CAST */ | 101 | (const unsigned char **)pp,length)) == NULL) /* TMP UGLY CAST */ |
102 | { | 102 | { |
103 | ASN1err(ASN1_F_D2I_PUBLICKEY,ERR_R_ASN1_LIB); | 103 | ASN1err(ASN1_F_D2I_PUBLICKEY,ERR_R_ASN1_LIB); |
104 | goto err; | 104 | goto err; |
105 | } | 105 | } |
106 | break; | 106 | break; |
107 | #endif | 107 | #endif |
108 | #ifndef OPENSSL_NO_DSA | 108 | #ifndef OPENSSL_NO_DSA |
109 | case EVP_PKEY_DSA: | 109 | case EVP_PKEY_DSA: |
110 | if (!d2i_DSAPublicKey(&(ret->pkey.dsa), | 110 | if (!d2i_DSAPublicKey(&(ret->pkey.dsa), |
111 | (const unsigned char **)pp,length)) /* TMP UGLY CAST */ | 111 | (const unsigned char **)pp,length)) /* TMP UGLY CAST */ |
112 | { | 112 | { |
113 | ASN1err(ASN1_F_D2I_PUBLICKEY,ERR_R_ASN1_LIB); | 113 | ASN1err(ASN1_F_D2I_PUBLICKEY,ERR_R_ASN1_LIB); |
114 | goto err; | 114 | goto err; |
115 | } | 115 | } |
116 | break; | 116 | break; |
117 | #endif | 117 | #endif |
118 | #ifndef OPENSSL_NO_EC | 118 | #ifndef OPENSSL_NO_EC |
119 | case EVP_PKEY_EC: | 119 | case EVP_PKEY_EC: |
120 | if (!o2i_ECPublicKey(&(ret->pkey.ec), | 120 | if (!o2i_ECPublicKey(&(ret->pkey.ec), |
121 | (const unsigned char **)pp, length)) | 121 | (const unsigned char **)pp, length)) |
122 | { | 122 | { |
123 | ASN1err(ASN1_F_D2I_PUBLICKEY, ERR_R_ASN1_LIB); | 123 | ASN1err(ASN1_F_D2I_PUBLICKEY, ERR_R_ASN1_LIB); |
124 | goto err; | 124 | goto err; |
125 | } | 125 | } |
126 | break; | 126 | break; |
127 | #endif | 127 | #endif |
128 | default: | 128 | default: |
129 | ASN1err(ASN1_F_D2I_PUBLICKEY,ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE); | 129 | ASN1err(ASN1_F_D2I_PUBLICKEY,ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE); |
130 | goto err; | 130 | goto err; |
131 | /* break; */ | 131 | /* break; */ |
132 | } | 132 | } |
133 | if (a != NULL) (*a)=ret; | 133 | if (a != NULL) (*a)=ret; |
134 | return(ret); | 134 | return(ret); |
135 | err: | 135 | err: |
136 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) EVP_PKEY_free(ret); | 136 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) EVP_PKEY_free(ret); |
137 | return(NULL); | 137 | return(NULL); |
138 | } | 138 | } |
139 | 139 | ||
diff --git a/src/lib/libcrypto/asn1/evp_asn1.c b/src/lib/libcrypto/asn1/evp_asn1.c index f3d9804860..631924f88e 100644 --- a/src/lib/libcrypto/asn1/evp_asn1.c +++ b/src/lib/libcrypto/asn1/evp_asn1.c | |||
@@ -62,27 +62,27 @@ | |||
62 | #include <openssl/asn1_mac.h> | 62 | #include <openssl/asn1_mac.h> |
63 | 63 | ||
64 | int ASN1_TYPE_set_octetstring(ASN1_TYPE *a, unsigned char *data, int len) | 64 | int ASN1_TYPE_set_octetstring(ASN1_TYPE *a, unsigned char *data, int len) |
65 | { | 65 | { |
66 | ASN1_STRING *os; | 66 | ASN1_STRING *os; |
67 | 67 | ||
68 | if ((os=M_ASN1_OCTET_STRING_new()) == NULL) return(0); | 68 | if ((os=M_ASN1_OCTET_STRING_new()) == NULL) return(0); |
69 | if (!M_ASN1_OCTET_STRING_set(os,data,len)) return(0); | 69 | if (!M_ASN1_OCTET_STRING_set(os,data,len)) return(0); |
70 | ASN1_TYPE_set(a,V_ASN1_OCTET_STRING,os); | 70 | ASN1_TYPE_set(a,V_ASN1_OCTET_STRING,os); |
71 | return(1); | 71 | return(1); |
72 | } | 72 | } |
73 | 73 | ||
74 | /* int max_len: for returned value */ | 74 | /* int max_len: for returned value */ |
75 | int ASN1_TYPE_get_octetstring(ASN1_TYPE *a, unsigned char *data, | 75 | int ASN1_TYPE_get_octetstring(ASN1_TYPE *a, unsigned char *data, |
76 | int max_len) | 76 | int max_len) |
77 | { | 77 | { |
78 | int ret,num; | 78 | int ret,num; |
79 | unsigned char *p; | 79 | unsigned char *p; |
80 | 80 | ||
81 | if ((a->type != V_ASN1_OCTET_STRING) || (a->value.octet_string == NULL)) | 81 | if ((a->type != V_ASN1_OCTET_STRING) || (a->value.octet_string == NULL)) |
82 | { | 82 | { |
83 | ASN1err(ASN1_F_ASN1_TYPE_GET_OCTETSTRING,ASN1_R_DATA_IS_WRONG); | 83 | ASN1err(ASN1_F_ASN1_TYPE_GET_OCTETSTRING,ASN1_R_DATA_IS_WRONG); |
84 | return(-1); | 84 | return(-1); |
85 | } | 85 | } |
86 | p=M_ASN1_STRING_data(a->value.octet_string); | 86 | p=M_ASN1_STRING_data(a->value.octet_string); |
87 | ret=M_ASN1_STRING_length(a->value.octet_string); | 87 | ret=M_ASN1_STRING_length(a->value.octet_string); |
88 | if (ret < max_len) | 88 | if (ret < max_len) |
@@ -91,11 +91,11 @@ int ASN1_TYPE_get_octetstring(ASN1_TYPE *a, unsigned char *data, | |||
91 | num=max_len; | 91 | num=max_len; |
92 | memcpy(data,p,num); | 92 | memcpy(data,p,num); |
93 | return(ret); | 93 | return(ret); |
94 | } | 94 | } |
95 | 95 | ||
96 | int ASN1_TYPE_set_int_octetstring(ASN1_TYPE *a, long num, unsigned char *data, | 96 | int ASN1_TYPE_set_int_octetstring(ASN1_TYPE *a, long num, unsigned char *data, |
97 | int len) | 97 | int len) |
98 | { | 98 | { |
99 | int n,size; | 99 | int n,size; |
100 | ASN1_OCTET_STRING os,*osp; | 100 | ASN1_OCTET_STRING os,*osp; |
101 | ASN1_INTEGER in; | 101 | ASN1_INTEGER in; |
@@ -116,10 +116,10 @@ int ASN1_TYPE_set_int_octetstring(ASN1_TYPE *a, long num, unsigned char *data, | |||
116 | if ((osp=ASN1_STRING_new()) == NULL) return(0); | 116 | if ((osp=ASN1_STRING_new()) == NULL) return(0); |
117 | /* Grow the 'string' */ | 117 | /* Grow the 'string' */ |
118 | if (!ASN1_STRING_set(osp,NULL,size)) | 118 | if (!ASN1_STRING_set(osp,NULL,size)) |
119 | { | 119 | { |
120 | ASN1_STRING_free(osp); | 120 | ASN1_STRING_free(osp); |
121 | return(0); | 121 | return(0); |
122 | } | 122 | } |
123 | 123 | ||
124 | M_ASN1_STRING_length_set(osp, size); | 124 | M_ASN1_STRING_length_set(osp, size); |
125 | p=M_ASN1_STRING_data(osp); | 125 | p=M_ASN1_STRING_data(osp); |
@@ -130,14 +130,14 @@ int ASN1_TYPE_set_int_octetstring(ASN1_TYPE *a, long num, unsigned char *data, | |||
130 | 130 | ||
131 | ASN1_TYPE_set(a,V_ASN1_SEQUENCE,osp); | 131 | ASN1_TYPE_set(a,V_ASN1_SEQUENCE,osp); |
132 | return(1); | 132 | return(1); |
133 | } | 133 | } |
134 | 134 | ||
135 | /* we return the actual length..., num may be missing, in which | 135 | /* we return the actual length..., num may be missing, in which |
136 | * case, set it to zero */ | 136 | * case, set it to zero */ |
137 | /* int max_len: for returned value */ | 137 | /* int max_len: for returned value */ |
138 | int ASN1_TYPE_get_int_octetstring(ASN1_TYPE *a, long *num, unsigned char *data, | 138 | int ASN1_TYPE_get_int_octetstring(ASN1_TYPE *a, long *num, unsigned char *data, |
139 | int max_len) | 139 | int max_len) |
140 | { | 140 | { |
141 | int ret= -1,n; | 141 | int ret= -1,n; |
142 | ASN1_INTEGER *ai=NULL; | 142 | ASN1_INTEGER *ai=NULL; |
143 | ASN1_OCTET_STRING *os=NULL; | 143 | ASN1_OCTET_STRING *os=NULL; |
@@ -146,9 +146,9 @@ int ASN1_TYPE_get_int_octetstring(ASN1_TYPE *a, long *num, unsigned char *data, | |||
146 | ASN1_const_CTX c; | 146 | ASN1_const_CTX c; |
147 | 147 | ||
148 | if ((a->type != V_ASN1_SEQUENCE) || (a->value.sequence == NULL)) | 148 | if ((a->type != V_ASN1_SEQUENCE) || (a->value.sequence == NULL)) |
149 | { | 149 | { |
150 | goto err; | 150 | goto err; |
151 | } | 151 | } |
152 | p=M_ASN1_STRING_data(a->value.sequence); | 152 | p=M_ASN1_STRING_data(a->value.sequence); |
153 | length=M_ASN1_STRING_length(a->value.sequence); | 153 | length=M_ASN1_STRING_length(a->value.sequence); |
154 | 154 | ||
@@ -178,12 +178,12 @@ int ASN1_TYPE_get_int_octetstring(ASN1_TYPE *a, long *num, unsigned char *data, | |||
178 | if (data != NULL) | 178 | if (data != NULL) |
179 | memcpy(data,M_ASN1_STRING_data(os),n); | 179 | memcpy(data,M_ASN1_STRING_data(os),n); |
180 | if (0) | 180 | if (0) |
181 | { | 181 | { |
182 | err: | 182 | err: |
183 | ASN1err(ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING,ASN1_R_DATA_IS_WRONG); | 183 | ASN1err(ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING,ASN1_R_DATA_IS_WRONG); |
184 | } | 184 | } |
185 | if (os != NULL) M_ASN1_OCTET_STRING_free(os); | 185 | if (os != NULL) M_ASN1_OCTET_STRING_free(os); |
186 | if (ai != NULL) M_ASN1_INTEGER_free(ai); | 186 | if (ai != NULL) M_ASN1_INTEGER_free(ai); |
187 | return(ret); | 187 | return(ret); |
188 | } | 188 | } |
189 | 189 | ||
diff --git a/src/lib/libcrypto/asn1/f_enum.c b/src/lib/libcrypto/asn1/f_enum.c index caf34ee97e..b6e66ab194 100644 --- a/src/lib/libcrypto/asn1/f_enum.c +++ b/src/lib/libcrypto/asn1/f_enum.c | |||
@@ -64,7 +64,7 @@ | |||
64 | /* Based on a_int.c: equivalent ENUMERATED functions */ | 64 | /* Based on a_int.c: equivalent ENUMERATED functions */ |
65 | 65 | ||
66 | int i2a_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *a) | 66 | int i2a_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *a) |
67 | { | 67 | { |
68 | int i,n=0; | 68 | int i,n=0; |
69 | static const char *h="0123456789ABCDEF"; | 69 | static const char *h="0123456789ABCDEF"; |
70 | char buf[2]; | 70 | char buf[2]; |
@@ -72,32 +72,32 @@ int i2a_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *a) | |||
72 | if (a == NULL) return(0); | 72 | if (a == NULL) return(0); |
73 | 73 | ||
74 | if (a->length == 0) | 74 | if (a->length == 0) |
75 | { | 75 | { |
76 | if (BIO_write(bp,"00",2) != 2) goto err; | 76 | if (BIO_write(bp,"00",2) != 2) goto err; |
77 | n=2; | 77 | n=2; |
78 | } | 78 | } |
79 | else | 79 | else |
80 | { | 80 | { |
81 | for (i=0; i<a->length; i++) | 81 | for (i=0; i<a->length; i++) |
82 | { | 82 | { |
83 | if ((i != 0) && (i%35 == 0)) | 83 | if ((i != 0) && (i%35 == 0)) |
84 | { | 84 | { |
85 | if (BIO_write(bp,"\\\n",2) != 2) goto err; | 85 | if (BIO_write(bp,"\\\n",2) != 2) goto err; |
86 | n+=2; | 86 | n+=2; |
87 | } | 87 | } |
88 | buf[0]=h[((unsigned char)a->data[i]>>4)&0x0f]; | 88 | buf[0]=h[((unsigned char)a->data[i]>>4)&0x0f]; |
89 | buf[1]=h[((unsigned char)a->data[i] )&0x0f]; | 89 | buf[1]=h[((unsigned char)a->data[i] )&0x0f]; |
90 | if (BIO_write(bp,buf,2) != 2) goto err; | 90 | if (BIO_write(bp,buf,2) != 2) goto err; |
91 | n+=2; | 91 | n+=2; |
92 | } | ||
93 | } | 92 | } |
93 | } | ||
94 | return(n); | 94 | return(n); |
95 | err: | 95 | err: |
96 | return(-1); | 96 | return(-1); |
97 | } | 97 | } |
98 | 98 | ||
99 | int a2i_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *bs, char *buf, int size) | 99 | int a2i_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *bs, char *buf, int size) |
100 | { | 100 | { |
101 | int ret=0; | 101 | int ret=0; |
102 | int i,j,k,m,n,again,bufsize; | 102 | int i,j,k,m,n,again,bufsize; |
103 | unsigned char *s=NULL,*sp; | 103 | unsigned char *s=NULL,*sp; |
@@ -108,7 +108,7 @@ int a2i_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *bs, char *buf, int size) | |||
108 | 108 | ||
109 | bufsize=BIO_gets(bp,buf,size); | 109 | bufsize=BIO_gets(bp,buf,size); |
110 | for (;;) | 110 | for (;;) |
111 | { | 111 | { |
112 | if (bufsize < 1) goto err_sl; | 112 | if (bufsize < 1) goto err_sl; |
113 | i=bufsize; | 113 | i=bufsize; |
114 | if (buf[i-1] == '\n') buf[--i]='\0'; | 114 | if (buf[i-1] == '\n') buf[--i]='\0'; |
@@ -118,15 +118,15 @@ int a2i_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *bs, char *buf, int size) | |||
118 | again=(buf[i-1] == '\\'); | 118 | again=(buf[i-1] == '\\'); |
119 | 119 | ||
120 | for (j=0; j<i; j++) | 120 | for (j=0; j<i; j++) |
121 | { | 121 | { |
122 | if (!( ((buf[j] >= '0') && (buf[j] <= '9')) || | 122 | if (!( ((buf[j] >= '0') && (buf[j] <= '9')) || |
123 | ((buf[j] >= 'a') && (buf[j] <= 'f')) || | 123 | ((buf[j] >= 'a') && (buf[j] <= 'f')) || |
124 | ((buf[j] >= 'A') && (buf[j] <= 'F')))) | 124 | ((buf[j] >= 'A') && (buf[j] <= 'F')))) |
125 | { | 125 | { |
126 | i=j; | 126 | i=j; |
127 | break; | 127 | break; |
128 | } | ||
129 | } | 128 | } |
129 | } | ||
130 | buf[i]='\0'; | 130 | buf[i]='\0'; |
131 | /* We have now cleared all the crap off the end of the | 131 | /* We have now cleared all the crap off the end of the |
132 | * line */ | 132 | * line */ |
@@ -134,24 +134,24 @@ int a2i_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *bs, char *buf, int size) | |||
134 | 134 | ||
135 | bufp=(unsigned char *)buf; | 135 | bufp=(unsigned char *)buf; |
136 | if (first) | 136 | if (first) |
137 | { | 137 | { |
138 | first=0; | 138 | first=0; |
139 | if ((bufp[0] == '0') && (buf[1] == '0')) | 139 | if ((bufp[0] == '0') && (buf[1] == '0')) |
140 | { | 140 | { |
141 | bufp+=2; | 141 | bufp+=2; |
142 | i-=2; | 142 | i-=2; |
143 | } | ||
144 | } | 143 | } |
144 | } | ||
145 | k=0; | 145 | k=0; |
146 | i-=again; | 146 | i-=again; |
147 | if (i%2 != 0) | 147 | if (i%2 != 0) |
148 | { | 148 | { |
149 | ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ASN1_R_ODD_NUMBER_OF_CHARS); | 149 | ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ASN1_R_ODD_NUMBER_OF_CHARS); |
150 | goto err; | 150 | goto err; |
151 | } | 151 | } |
152 | i/=2; | 152 | i/=2; |
153 | if (num+i > slen) | 153 | if (num+i > slen) |
154 | { | 154 | { |
155 | if (s == NULL) | 155 | if (s == NULL) |
156 | sp=(unsigned char *)malloc( | 156 | sp=(unsigned char *)malloc( |
157 | (unsigned int)num+i*2); | 157 | (unsigned int)num+i*2); |
@@ -159,18 +159,18 @@ int a2i_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *bs, char *buf, int size) | |||
159 | sp=(unsigned char *)realloc(s, | 159 | sp=(unsigned char *)realloc(s, |
160 | (unsigned int)num+i*2); | 160 | (unsigned int)num+i*2); |
161 | if (sp == NULL) | 161 | if (sp == NULL) |
162 | { | 162 | { |
163 | ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ERR_R_MALLOC_FAILURE); | 163 | ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ERR_R_MALLOC_FAILURE); |
164 | if (s != NULL) free(s); | 164 | if (s != NULL) free(s); |
165 | goto err; | 165 | goto err; |
166 | } | 166 | } |
167 | s=sp; | 167 | s=sp; |
168 | slen=num+i*2; | 168 | slen=num+i*2; |
169 | } | 169 | } |
170 | for (j=0; j<i; j++,k+=2) | 170 | for (j=0; j<i; j++,k+=2) |
171 | { | 171 | { |
172 | for (n=0; n<2; n++) | 172 | for (n=0; n<2; n++) |
173 | { | 173 | { |
174 | m=bufp[k+n]; | 174 | m=bufp[k+n]; |
175 | if ((m >= '0') && (m <= '9')) | 175 | if ((m >= '0') && (m <= '9')) |
176 | m-='0'; | 176 | m-='0'; |
@@ -179,29 +179,29 @@ int a2i_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *bs, char *buf, int size) | |||
179 | else if ((m >= 'A') && (m <= 'F')) | 179 | else if ((m >= 'A') && (m <= 'F')) |
180 | m=m-'A'+10; | 180 | m=m-'A'+10; |
181 | else | 181 | else |
182 | { | 182 | { |
183 | ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ASN1_R_NON_HEX_CHARACTERS); | 183 | ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ASN1_R_NON_HEX_CHARACTERS); |
184 | goto err; | 184 | goto err; |
185 | } | 185 | } |
186 | s[num+j]<<=4; | 186 | s[num+j]<<=4; |
187 | s[num+j]|=m; | 187 | s[num+j]|=m; |
188 | } | ||
189 | } | 188 | } |
189 | } | ||
190 | num+=i; | 190 | num+=i; |
191 | if (again) | 191 | if (again) |
192 | bufsize=BIO_gets(bp,buf,size); | 192 | bufsize=BIO_gets(bp,buf,size); |
193 | else | 193 | else |
194 | break; | 194 | break; |
195 | } | 195 | } |
196 | bs->length=num; | 196 | bs->length=num; |
197 | bs->data=s; | 197 | bs->data=s; |
198 | ret=1; | 198 | ret=1; |
199 | err: | 199 | err: |
200 | if (0) | 200 | if (0) |
201 | { | 201 | { |
202 | err_sl: | 202 | err_sl: |
203 | ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ASN1_R_SHORT_LINE); | 203 | ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ASN1_R_SHORT_LINE); |
204 | } | ||
205 | return(ret); | ||
206 | } | 204 | } |
205 | return(ret); | ||
206 | } | ||
207 | 207 | ||
diff --git a/src/lib/libcrypto/asn1/f_int.c b/src/lib/libcrypto/asn1/f_int.c index 977e3d01b7..66632f2dc4 100644 --- a/src/lib/libcrypto/asn1/f_int.c +++ b/src/lib/libcrypto/asn1/f_int.c | |||
@@ -62,7 +62,7 @@ | |||
62 | #include <openssl/asn1.h> | 62 | #include <openssl/asn1.h> |
63 | 63 | ||
64 | int i2a_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *a) | 64 | int i2a_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *a) |
65 | { | 65 | { |
66 | int i,n=0; | 66 | int i,n=0; |
67 | static const char *h="0123456789ABCDEF"; | 67 | static const char *h="0123456789ABCDEF"; |
68 | char buf[2]; | 68 | char buf[2]; |
@@ -70,38 +70,38 @@ int i2a_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *a) | |||
70 | if (a == NULL) return(0); | 70 | if (a == NULL) return(0); |
71 | 71 | ||
72 | if (a->type & V_ASN1_NEG) | 72 | if (a->type & V_ASN1_NEG) |
73 | { | 73 | { |
74 | if (BIO_write(bp, "-", 1) != 1) goto err; | 74 | if (BIO_write(bp, "-", 1) != 1) goto err; |
75 | n = 1; | 75 | n = 1; |
76 | } | 76 | } |
77 | 77 | ||
78 | if (a->length == 0) | 78 | if (a->length == 0) |
79 | { | 79 | { |
80 | if (BIO_write(bp,"00",2) != 2) goto err; | 80 | if (BIO_write(bp,"00",2) != 2) goto err; |
81 | n += 2; | 81 | n += 2; |
82 | } | 82 | } |
83 | else | 83 | else |
84 | { | 84 | { |
85 | for (i=0; i<a->length; i++) | 85 | for (i=0; i<a->length; i++) |
86 | { | 86 | { |
87 | if ((i != 0) && (i%35 == 0)) | 87 | if ((i != 0) && (i%35 == 0)) |
88 | { | 88 | { |
89 | if (BIO_write(bp,"\\\n",2) != 2) goto err; | 89 | if (BIO_write(bp,"\\\n",2) != 2) goto err; |
90 | n+=2; | 90 | n+=2; |
91 | } | 91 | } |
92 | buf[0]=h[((unsigned char)a->data[i]>>4)&0x0f]; | 92 | buf[0]=h[((unsigned char)a->data[i]>>4)&0x0f]; |
93 | buf[1]=h[((unsigned char)a->data[i] )&0x0f]; | 93 | buf[1]=h[((unsigned char)a->data[i] )&0x0f]; |
94 | if (BIO_write(bp,buf,2) != 2) goto err; | 94 | if (BIO_write(bp,buf,2) != 2) goto err; |
95 | n+=2; | 95 | n+=2; |
96 | } | ||
97 | } | 96 | } |
97 | } | ||
98 | return(n); | 98 | return(n); |
99 | err: | 99 | err: |
100 | return(-1); | 100 | return(-1); |
101 | } | 101 | } |
102 | 102 | ||
103 | int a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size) | 103 | int a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size) |
104 | { | 104 | { |
105 | int ret=0; | 105 | int ret=0; |
106 | int i,j,k,m,n,again,bufsize; | 106 | int i,j,k,m,n,again,bufsize; |
107 | unsigned char *s=NULL,*sp; | 107 | unsigned char *s=NULL,*sp; |
@@ -112,7 +112,7 @@ int a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size) | |||
112 | 112 | ||
113 | bufsize=BIO_gets(bp,buf,size); | 113 | bufsize=BIO_gets(bp,buf,size); |
114 | for (;;) | 114 | for (;;) |
115 | { | 115 | { |
116 | if (bufsize < 1) goto err_sl; | 116 | if (bufsize < 1) goto err_sl; |
117 | i=bufsize; | 117 | i=bufsize; |
118 | if (buf[i-1] == '\n') buf[--i]='\0'; | 118 | if (buf[i-1] == '\n') buf[--i]='\0'; |
@@ -122,15 +122,15 @@ int a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size) | |||
122 | again=(buf[i-1] == '\\'); | 122 | again=(buf[i-1] == '\\'); |
123 | 123 | ||
124 | for (j=0; j<i; j++) | 124 | for (j=0; j<i; j++) |
125 | { | 125 | { |
126 | if (!( ((buf[j] >= '0') && (buf[j] <= '9')) || | 126 | if (!( ((buf[j] >= '0') && (buf[j] <= '9')) || |
127 | ((buf[j] >= 'a') && (buf[j] <= 'f')) || | 127 | ((buf[j] >= 'a') && (buf[j] <= 'f')) || |
128 | ((buf[j] >= 'A') && (buf[j] <= 'F')))) | 128 | ((buf[j] >= 'A') && (buf[j] <= 'F')))) |
129 | { | 129 | { |
130 | i=j; | 130 | i=j; |
131 | break; | 131 | break; |
132 | } | ||
133 | } | 132 | } |
133 | } | ||
134 | buf[i]='\0'; | 134 | buf[i]='\0'; |
135 | /* We have now cleared all the crap off the end of the | 135 | /* We have now cleared all the crap off the end of the |
136 | * line */ | 136 | * line */ |
@@ -138,42 +138,42 @@ int a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size) | |||
138 | 138 | ||
139 | bufp=(unsigned char *)buf; | 139 | bufp=(unsigned char *)buf; |
140 | if (first) | 140 | if (first) |
141 | { | 141 | { |
142 | first=0; | 142 | first=0; |
143 | if ((bufp[0] == '0') && (buf[1] == '0')) | 143 | if ((bufp[0] == '0') && (buf[1] == '0')) |
144 | { | 144 | { |
145 | bufp+=2; | 145 | bufp+=2; |
146 | i-=2; | 146 | i-=2; |
147 | } | ||
148 | } | 147 | } |
148 | } | ||
149 | k=0; | 149 | k=0; |
150 | i-=again; | 150 | i-=again; |
151 | if (i%2 != 0) | 151 | if (i%2 != 0) |
152 | { | 152 | { |
153 | ASN1err(ASN1_F_A2I_ASN1_INTEGER,ASN1_R_ODD_NUMBER_OF_CHARS); | 153 | ASN1err(ASN1_F_A2I_ASN1_INTEGER,ASN1_R_ODD_NUMBER_OF_CHARS); |
154 | goto err; | 154 | goto err; |
155 | } | 155 | } |
156 | i/=2; | 156 | i/=2; |
157 | if (num+i > slen) | 157 | if (num+i > slen) |
158 | { | 158 | { |
159 | if (s == NULL) | 159 | if (s == NULL) |
160 | sp=(unsigned char *)malloc( | 160 | sp=(unsigned char *)malloc( |
161 | (unsigned int)num+i*2); | 161 | (unsigned int)num+i*2); |
162 | else | 162 | else |
163 | sp=OPENSSL_realloc_clean(s,slen,num+i*2); | 163 | sp=OPENSSL_realloc_clean(s,slen,num+i*2); |
164 | if (sp == NULL) | 164 | if (sp == NULL) |
165 | { | 165 | { |
166 | ASN1err(ASN1_F_A2I_ASN1_INTEGER,ERR_R_MALLOC_FAILURE); | 166 | ASN1err(ASN1_F_A2I_ASN1_INTEGER,ERR_R_MALLOC_FAILURE); |
167 | if (s != NULL) free(s); | 167 | if (s != NULL) free(s); |
168 | goto err; | 168 | goto err; |
169 | } | 169 | } |
170 | s=sp; | 170 | s=sp; |
171 | slen=num+i*2; | 171 | slen=num+i*2; |
172 | } | 172 | } |
173 | for (j=0; j<i; j++,k+=2) | 173 | for (j=0; j<i; j++,k+=2) |
174 | { | 174 | { |
175 | for (n=0; n<2; n++) | 175 | for (n=0; n<2; n++) |
176 | { | 176 | { |
177 | m=bufp[k+n]; | 177 | m=bufp[k+n]; |
178 | if ((m >= '0') && (m <= '9')) | 178 | if ((m >= '0') && (m <= '9')) |
179 | m-='0'; | 179 | m-='0'; |
@@ -182,29 +182,29 @@ int a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size) | |||
182 | else if ((m >= 'A') && (m <= 'F')) | 182 | else if ((m >= 'A') && (m <= 'F')) |
183 | m=m-'A'+10; | 183 | m=m-'A'+10; |
184 | else | 184 | else |
185 | { | 185 | { |
186 | ASN1err(ASN1_F_A2I_ASN1_INTEGER,ASN1_R_NON_HEX_CHARACTERS); | 186 | ASN1err(ASN1_F_A2I_ASN1_INTEGER,ASN1_R_NON_HEX_CHARACTERS); |
187 | goto err; | 187 | goto err; |
188 | } | 188 | } |
189 | s[num+j]<<=4; | 189 | s[num+j]<<=4; |
190 | s[num+j]|=m; | 190 | s[num+j]|=m; |
191 | } | ||
192 | } | 191 | } |
192 | } | ||
193 | num+=i; | 193 | num+=i; |
194 | if (again) | 194 | if (again) |
195 | bufsize=BIO_gets(bp,buf,size); | 195 | bufsize=BIO_gets(bp,buf,size); |
196 | else | 196 | else |
197 | break; | 197 | break; |
198 | } | 198 | } |
199 | bs->length=num; | 199 | bs->length=num; |
200 | bs->data=s; | 200 | bs->data=s; |
201 | ret=1; | 201 | ret=1; |
202 | err: | 202 | err: |
203 | if (0) | 203 | if (0) |
204 | { | 204 | { |
205 | err_sl: | 205 | err_sl: |
206 | ASN1err(ASN1_F_A2I_ASN1_INTEGER,ASN1_R_SHORT_LINE); | 206 | ASN1err(ASN1_F_A2I_ASN1_INTEGER,ASN1_R_SHORT_LINE); |
207 | } | ||
208 | return(ret); | ||
209 | } | 207 | } |
208 | return(ret); | ||
209 | } | ||
210 | 210 | ||
diff --git a/src/lib/libcrypto/asn1/f_string.c b/src/lib/libcrypto/asn1/f_string.c index f4bee15335..7a59fa9f4f 100644 --- a/src/lib/libcrypto/asn1/f_string.c +++ b/src/lib/libcrypto/asn1/f_string.c | |||
@@ -62,7 +62,7 @@ | |||
62 | #include <openssl/asn1.h> | 62 | #include <openssl/asn1.h> |
63 | 63 | ||
64 | int i2a_ASN1_STRING(BIO *bp, ASN1_STRING *a, int type) | 64 | int i2a_ASN1_STRING(BIO *bp, ASN1_STRING *a, int type) |
65 | { | 65 | { |
66 | int i,n=0; | 66 | int i,n=0; |
67 | static const char *h="0123456789ABCDEF"; | 67 | static const char *h="0123456789ABCDEF"; |
68 | char buf[2]; | 68 | char buf[2]; |
@@ -70,32 +70,32 @@ int i2a_ASN1_STRING(BIO *bp, ASN1_STRING *a, int type) | |||
70 | if (a == NULL) return(0); | 70 | if (a == NULL) return(0); |
71 | 71 | ||
72 | if (a->length == 0) | 72 | if (a->length == 0) |
73 | { | 73 | { |
74 | if (BIO_write(bp,"0",1) != 1) goto err; | 74 | if (BIO_write(bp,"0",1) != 1) goto err; |
75 | n=1; | 75 | n=1; |
76 | } | 76 | } |
77 | else | 77 | else |
78 | { | 78 | { |
79 | for (i=0; i<a->length; i++) | 79 | for (i=0; i<a->length; i++) |
80 | { | 80 | { |
81 | if ((i != 0) && (i%35 == 0)) | 81 | if ((i != 0) && (i%35 == 0)) |
82 | { | 82 | { |
83 | if (BIO_write(bp,"\\\n",2) != 2) goto err; | 83 | if (BIO_write(bp,"\\\n",2) != 2) goto err; |
84 | n+=2; | 84 | n+=2; |
85 | } | 85 | } |
86 | buf[0]=h[((unsigned char)a->data[i]>>4)&0x0f]; | 86 | buf[0]=h[((unsigned char)a->data[i]>>4)&0x0f]; |
87 | buf[1]=h[((unsigned char)a->data[i] )&0x0f]; | 87 | buf[1]=h[((unsigned char)a->data[i] )&0x0f]; |
88 | if (BIO_write(bp,buf,2) != 2) goto err; | 88 | if (BIO_write(bp,buf,2) != 2) goto err; |
89 | n+=2; | 89 | n+=2; |
90 | } | ||
91 | } | 90 | } |
91 | } | ||
92 | return(n); | 92 | return(n); |
93 | err: | 93 | err: |
94 | return(-1); | 94 | return(-1); |
95 | } | 95 | } |
96 | 96 | ||
97 | int a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size) | 97 | int a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size) |
98 | { | 98 | { |
99 | int ret=0; | 99 | int ret=0; |
100 | int i,j,k,m,n,again,bufsize; | 100 | int i,j,k,m,n,again,bufsize; |
101 | unsigned char *s=NULL,*sp; | 101 | unsigned char *s=NULL,*sp; |
@@ -104,14 +104,14 @@ int a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size) | |||
104 | 104 | ||
105 | bufsize=BIO_gets(bp,buf,size); | 105 | bufsize=BIO_gets(bp,buf,size); |
106 | for (;;) | 106 | for (;;) |
107 | { | 107 | { |
108 | if (bufsize < 1) | 108 | if (bufsize < 1) |
109 | { | 109 | { |
110 | if (first) | 110 | if (first) |
111 | break; | 111 | break; |
112 | else | 112 | else |
113 | goto err_sl; | 113 | goto err_sl; |
114 | } | 114 | } |
115 | first=0; | 115 | first=0; |
116 | 116 | ||
117 | i=bufsize; | 117 | i=bufsize; |
@@ -122,15 +122,15 @@ int a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size) | |||
122 | again=(buf[i-1] == '\\'); | 122 | again=(buf[i-1] == '\\'); |
123 | 123 | ||
124 | for (j=i-1; j>0; j--) | 124 | for (j=i-1; j>0; j--) |
125 | { | 125 | { |
126 | if (!( ((buf[j] >= '0') && (buf[j] <= '9')) || | 126 | if (!( ((buf[j] >= '0') && (buf[j] <= '9')) || |
127 | ((buf[j] >= 'a') && (buf[j] <= 'f')) || | 127 | ((buf[j] >= 'a') && (buf[j] <= 'f')) || |
128 | ((buf[j] >= 'A') && (buf[j] <= 'F')))) | 128 | ((buf[j] >= 'A') && (buf[j] <= 'F')))) |
129 | { | 129 | { |
130 | i=j; | 130 | i=j; |
131 | break; | 131 | break; |
132 | } | ||
133 | } | 132 | } |
133 | } | ||
134 | buf[i]='\0'; | 134 | buf[i]='\0'; |
135 | /* We have now cleared all the crap off the end of the | 135 | /* We have now cleared all the crap off the end of the |
136 | * line */ | 136 | * line */ |
@@ -141,13 +141,13 @@ int a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size) | |||
141 | k=0; | 141 | k=0; |
142 | i-=again; | 142 | i-=again; |
143 | if (i%2 != 0) | 143 | if (i%2 != 0) |
144 | { | 144 | { |
145 | ASN1err(ASN1_F_A2I_ASN1_STRING,ASN1_R_ODD_NUMBER_OF_CHARS); | 145 | ASN1err(ASN1_F_A2I_ASN1_STRING,ASN1_R_ODD_NUMBER_OF_CHARS); |
146 | goto err; | 146 | goto err; |
147 | } | 147 | } |
148 | i/=2; | 148 | i/=2; |
149 | if (num+i > slen) | 149 | if (num+i > slen) |
150 | { | 150 | { |
151 | if (s == NULL) | 151 | if (s == NULL) |
152 | sp=(unsigned char *)malloc( | 152 | sp=(unsigned char *)malloc( |
153 | (unsigned int)num+i*2); | 153 | (unsigned int)num+i*2); |
@@ -155,18 +155,18 @@ int a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size) | |||
155 | sp=(unsigned char *)realloc(s, | 155 | sp=(unsigned char *)realloc(s, |
156 | (unsigned int)num+i*2); | 156 | (unsigned int)num+i*2); |
157 | if (sp == NULL) | 157 | if (sp == NULL) |
158 | { | 158 | { |
159 | ASN1err(ASN1_F_A2I_ASN1_STRING,ERR_R_MALLOC_FAILURE); | 159 | ASN1err(ASN1_F_A2I_ASN1_STRING,ERR_R_MALLOC_FAILURE); |
160 | if (s != NULL) free(s); | 160 | if (s != NULL) free(s); |
161 | goto err; | 161 | goto err; |
162 | } | 162 | } |
163 | s=sp; | 163 | s=sp; |
164 | slen=num+i*2; | 164 | slen=num+i*2; |
165 | } | 165 | } |
166 | for (j=0; j<i; j++,k+=2) | 166 | for (j=0; j<i; j++,k+=2) |
167 | { | 167 | { |
168 | for (n=0; n<2; n++) | 168 | for (n=0; n<2; n++) |
169 | { | 169 | { |
170 | m=bufp[k+n]; | 170 | m=bufp[k+n]; |
171 | if ((m >= '0') && (m <= '9')) | 171 | if ((m >= '0') && (m <= '9')) |
172 | m-='0'; | 172 | m-='0'; |
@@ -175,29 +175,29 @@ int a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size) | |||
175 | else if ((m >= 'A') && (m <= 'F')) | 175 | else if ((m >= 'A') && (m <= 'F')) |
176 | m=m-'A'+10; | 176 | m=m-'A'+10; |
177 | else | 177 | else |
178 | { | 178 | { |
179 | ASN1err(ASN1_F_A2I_ASN1_STRING,ASN1_R_NON_HEX_CHARACTERS); | 179 | ASN1err(ASN1_F_A2I_ASN1_STRING,ASN1_R_NON_HEX_CHARACTERS); |
180 | goto err; | 180 | goto err; |
181 | } | 181 | } |
182 | s[num+j]<<=4; | 182 | s[num+j]<<=4; |
183 | s[num+j]|=m; | 183 | s[num+j]|=m; |
184 | } | ||
185 | } | 184 | } |
185 | } | ||
186 | num+=i; | 186 | num+=i; |
187 | if (again) | 187 | if (again) |
188 | bufsize=BIO_gets(bp,buf,size); | 188 | bufsize=BIO_gets(bp,buf,size); |
189 | else | 189 | else |
190 | break; | 190 | break; |
191 | } | 191 | } |
192 | bs->length=num; | 192 | bs->length=num; |
193 | bs->data=s; | 193 | bs->data=s; |
194 | ret=1; | 194 | ret=1; |
195 | err: | 195 | err: |
196 | if (0) | 196 | if (0) |
197 | { | 197 | { |
198 | err_sl: | 198 | err_sl: |
199 | ASN1err(ASN1_F_A2I_ASN1_STRING,ASN1_R_SHORT_LINE); | 199 | ASN1err(ASN1_F_A2I_ASN1_STRING,ASN1_R_SHORT_LINE); |
200 | } | ||
201 | return(ret); | ||
202 | } | 200 | } |
201 | return(ret); | ||
202 | } | ||
203 | 203 | ||
diff --git a/src/lib/libcrypto/asn1/i2d_pr.c b/src/lib/libcrypto/asn1/i2d_pr.c index e398b62666..9332c4d2ec 100644 --- a/src/lib/libcrypto/asn1/i2d_pr.c +++ b/src/lib/libcrypto/asn1/i2d_pr.c | |||
@@ -63,18 +63,18 @@ | |||
63 | #include "asn1_locl.h" | 63 | #include "asn1_locl.h" |
64 | 64 | ||
65 | int i2d_PrivateKey(EVP_PKEY *a, unsigned char **pp) | 65 | int i2d_PrivateKey(EVP_PKEY *a, unsigned char **pp) |
66 | { | 66 | { |
67 | if (a->ameth && a->ameth->old_priv_encode) | 67 | if (a->ameth && a->ameth->old_priv_encode) |
68 | { | 68 | { |
69 | return a->ameth->old_priv_encode(a, pp); | 69 | return a->ameth->old_priv_encode(a, pp); |
70 | } | 70 | } |
71 | if (a->ameth && a->ameth->priv_encode) { | 71 | if (a->ameth && a->ameth->priv_encode) { |
72 | PKCS8_PRIV_KEY_INFO *p8 = EVP_PKEY2PKCS8(a); | 72 | PKCS8_PRIV_KEY_INFO *p8 = EVP_PKEY2PKCS8(a); |
73 | int ret = i2d_PKCS8_PRIV_KEY_INFO(p8,pp); | 73 | int ret = i2d_PKCS8_PRIV_KEY_INFO(p8,pp); |
74 | PKCS8_PRIV_KEY_INFO_free(p8); | 74 | PKCS8_PRIV_KEY_INFO_free(p8); |
75 | return ret; | 75 | return ret; |
76 | } | 76 | } |
77 | ASN1err(ASN1_F_I2D_PRIVATEKEY,ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE); | 77 | ASN1err(ASN1_F_I2D_PRIVATEKEY,ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE); |
78 | return(-1); | 78 | return(-1); |
79 | } | 79 | } |
80 | 80 | ||
diff --git a/src/lib/libcrypto/asn1/i2d_pu.c b/src/lib/libcrypto/asn1/i2d_pu.c index 34286dbd35..ed8ec0753b 100644 --- a/src/lib/libcrypto/asn1/i2d_pu.c +++ b/src/lib/libcrypto/asn1/i2d_pu.c | |||
@@ -72,9 +72,9 @@ | |||
72 | #endif | 72 | #endif |
73 | 73 | ||
74 | int i2d_PublicKey(EVP_PKEY *a, unsigned char **pp) | 74 | int i2d_PublicKey(EVP_PKEY *a, unsigned char **pp) |
75 | { | 75 | { |
76 | switch (a->type) | 76 | switch (a->type) |
77 | { | 77 | { |
78 | #ifndef OPENSSL_NO_RSA | 78 | #ifndef OPENSSL_NO_RSA |
79 | case EVP_PKEY_RSA: | 79 | case EVP_PKEY_RSA: |
80 | return(i2d_RSAPublicKey(a->pkey.rsa,pp)); | 80 | return(i2d_RSAPublicKey(a->pkey.rsa,pp)); |
@@ -90,6 +90,6 @@ int i2d_PublicKey(EVP_PKEY *a, unsigned char **pp) | |||
90 | default: | 90 | default: |
91 | ASN1err(ASN1_F_I2D_PUBLICKEY,ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE); | 91 | ASN1err(ASN1_F_I2D_PUBLICKEY,ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE); |
92 | return(-1); | 92 | return(-1); |
93 | } | ||
94 | } | 93 | } |
94 | } | ||
95 | 95 | ||
diff --git a/src/lib/libcrypto/asn1/n_pkey.c b/src/lib/libcrypto/asn1/n_pkey.c index 97647d17e1..a59640582e 100644 --- a/src/lib/libcrypto/asn1/n_pkey.c +++ b/src/lib/libcrypto/asn1/n_pkey.c | |||
@@ -70,21 +70,21 @@ | |||
70 | #ifndef OPENSSL_NO_RC4 | 70 | #ifndef OPENSSL_NO_RC4 |
71 | 71 | ||
72 | typedef struct netscape_pkey_st | 72 | typedef struct netscape_pkey_st |
73 | { | 73 | { |
74 | long version; | 74 | long version; |
75 | X509_ALGOR *algor; | 75 | X509_ALGOR *algor; |
76 | ASN1_OCTET_STRING *private_key; | 76 | ASN1_OCTET_STRING *private_key; |
77 | } NETSCAPE_PKEY; | 77 | } NETSCAPE_PKEY; |
78 | 78 | ||
79 | typedef struct netscape_encrypted_pkey_st | 79 | typedef struct netscape_encrypted_pkey_st |
80 | { | 80 | { |
81 | ASN1_OCTET_STRING *os; | 81 | ASN1_OCTET_STRING *os; |
82 | /* This is the same structure as DigestInfo so use it: | 82 | /* This is the same structure as DigestInfo so use it: |
83 | * although this isn't really anything to do with | 83 | * although this isn't really anything to do with |
84 | * digests. | 84 | * digests. |
85 | */ | 85 | */ |
86 | X509_SIG *enckey; | 86 | X509_SIG *enckey; |
87 | } NETSCAPE_ENCRYPTED_PKEY; | 87 | } NETSCAPE_ENCRYPTED_PKEY; |
88 | 88 | ||
89 | 89 | ||
90 | ASN1_BROKEN_SEQUENCE(NETSCAPE_ENCRYPTED_PKEY) = { | 90 | ASN1_BROKEN_SEQUENCE(NETSCAPE_ENCRYPTED_PKEY) = { |
@@ -121,7 +121,7 @@ int i2d_Netscape_RSA(const RSA *a, unsigned char **pp, | |||
121 | int i2d_RSA_NET(const RSA *a, unsigned char **pp, | 121 | int i2d_RSA_NET(const RSA *a, unsigned char **pp, |
122 | int (*cb)(char *buf, int len, const char *prompt, int verify), | 122 | int (*cb)(char *buf, int len, const char *prompt, int verify), |
123 | int sgckey) | 123 | int sgckey) |
124 | { | 124 | { |
125 | int i, j, ret = 0; | 125 | int i, j, ret = 0; |
126 | int rsalen, pkeylen, olen; | 126 | int rsalen, pkeylen, olen; |
127 | NETSCAPE_PKEY *pkey = NULL; | 127 | NETSCAPE_PKEY *pkey = NULL; |
@@ -160,36 +160,36 @@ int i2d_RSA_NET(const RSA *a, unsigned char **pp, | |||
160 | enckey->enckey->algor->parameter->type=V_ASN1_NULL; | 160 | enckey->enckey->algor->parameter->type=V_ASN1_NULL; |
161 | 161 | ||
162 | if (pp == NULL) | 162 | if (pp == NULL) |
163 | { | 163 | { |
164 | olen = i2d_NETSCAPE_ENCRYPTED_PKEY(enckey, NULL); | 164 | olen = i2d_NETSCAPE_ENCRYPTED_PKEY(enckey, NULL); |
165 | NETSCAPE_PKEY_free(pkey); | 165 | NETSCAPE_PKEY_free(pkey); |
166 | NETSCAPE_ENCRYPTED_PKEY_free(enckey); | 166 | NETSCAPE_ENCRYPTED_PKEY_free(enckey); |
167 | return olen; | 167 | return olen; |
168 | } | 168 | } |
169 | 169 | ||
170 | 170 | ||
171 | /* Since its RC4 encrypted length is actual length */ | 171 | /* Since its RC4 encrypted length is actual length */ |
172 | if ((zz=(unsigned char *)malloc(rsalen)) == NULL) | 172 | if ((zz=(unsigned char *)malloc(rsalen)) == NULL) |
173 | { | 173 | { |
174 | ASN1err(ASN1_F_I2D_RSA_NET,ERR_R_MALLOC_FAILURE); | 174 | ASN1err(ASN1_F_I2D_RSA_NET,ERR_R_MALLOC_FAILURE); |
175 | goto err; | 175 | goto err; |
176 | } | 176 | } |
177 | 177 | ||
178 | pkey->private_key->data = zz; | 178 | pkey->private_key->data = zz; |
179 | /* Write out private key encoding */ | 179 | /* Write out private key encoding */ |
180 | i2d_RSAPrivateKey(a,&zz); | 180 | i2d_RSAPrivateKey(a,&zz); |
181 | 181 | ||
182 | if ((zz=malloc(pkeylen)) == NULL) | 182 | if ((zz=malloc(pkeylen)) == NULL) |
183 | { | 183 | { |
184 | ASN1err(ASN1_F_I2D_RSA_NET,ERR_R_MALLOC_FAILURE); | 184 | ASN1err(ASN1_F_I2D_RSA_NET,ERR_R_MALLOC_FAILURE); |
185 | goto err; | 185 | goto err; |
186 | } | 186 | } |
187 | 187 | ||
188 | if (!ASN1_STRING_set(enckey->os, "private-key", -1)) | 188 | if (!ASN1_STRING_set(enckey->os, "private-key", -1)) |
189 | { | 189 | { |
190 | ASN1err(ASN1_F_I2D_RSA_NET,ERR_R_MALLOC_FAILURE); | 190 | ASN1err(ASN1_F_I2D_RSA_NET,ERR_R_MALLOC_FAILURE); |
191 | goto err; | 191 | goto err; |
192 | } | 192 | } |
193 | enckey->enckey->digest->data = zz; | 193 | enckey->enckey->digest->data = zz; |
194 | i2d_NETSCAPE_PKEY(pkey,&zz); | 194 | i2d_NETSCAPE_PKEY(pkey,&zz); |
195 | 195 | ||
@@ -200,10 +200,10 @@ int i2d_RSA_NET(const RSA *a, unsigned char **pp, | |||
200 | cb=EVP_read_pw_string; | 200 | cb=EVP_read_pw_string; |
201 | i=cb((char *)buf,256,"Enter Private Key password:",1); | 201 | i=cb((char *)buf,256,"Enter Private Key password:",1); |
202 | if (i != 0) | 202 | if (i != 0) |
203 | { | 203 | { |
204 | ASN1err(ASN1_F_I2D_RSA_NET,ASN1_R_BAD_PASSWORD_READ); | 204 | ASN1err(ASN1_F_I2D_RSA_NET,ASN1_R_BAD_PASSWORD_READ); |
205 | goto err; | 205 | goto err; |
206 | } | 206 | } |
207 | i = strlen((char *)buf); | 207 | i = strlen((char *)buf); |
208 | /* If the key is used for SGC the algorithm is modified a little. */ | 208 | /* If the key is used for SGC the algorithm is modified a little. */ |
209 | if(sgckey) { | 209 | if(sgckey) { |
@@ -211,7 +211,7 @@ int i2d_RSA_NET(const RSA *a, unsigned char **pp, | |||
211 | goto err; | 211 | goto err; |
212 | memcpy(buf + 16, "SGCKEYSALT", 10); | 212 | memcpy(buf + 16, "SGCKEYSALT", 10); |
213 | i = 26; | 213 | i = 26; |
214 | } | 214 | } |
215 | 215 | ||
216 | if (!EVP_BytesToKey(EVP_rc4(),EVP_md5(),NULL,buf,i,1,key,NULL)) | 216 | if (!EVP_BytesToKey(EVP_rc4(),EVP_md5(),NULL,buf,i,1,key,NULL)) |
217 | goto err; | 217 | goto err; |
@@ -232,7 +232,7 @@ err: | |||
232 | NETSCAPE_ENCRYPTED_PKEY_free(enckey); | 232 | NETSCAPE_ENCRYPTED_PKEY_free(enckey); |
233 | NETSCAPE_PKEY_free(pkey); | 233 | NETSCAPE_PKEY_free(pkey); |
234 | return(ret); | 234 | return(ret); |
235 | } | 235 | } |
236 | 236 | ||
237 | 237 | ||
238 | RSA *d2i_Netscape_RSA(RSA **a, const unsigned char **pp, long length, | 238 | RSA *d2i_Netscape_RSA(RSA **a, const unsigned char **pp, long length, |
@@ -245,7 +245,7 @@ RSA *d2i_Netscape_RSA(RSA **a, const unsigned char **pp, long length, | |||
245 | RSA *d2i_RSA_NET(RSA **a, const unsigned char **pp, long length, | 245 | RSA *d2i_RSA_NET(RSA **a, const unsigned char **pp, long length, |
246 | int (*cb)(char *buf, int len, const char *prompt, int verify), | 246 | int (*cb)(char *buf, int len, const char *prompt, int verify), |
247 | int sgckey) | 247 | int sgckey) |
248 | { | 248 | { |
249 | RSA *ret=NULL; | 249 | RSA *ret=NULL; |
250 | const unsigned char *p; | 250 | const unsigned char *p; |
251 | NETSCAPE_ENCRYPTED_PKEY *enckey = NULL; | 251 | NETSCAPE_ENCRYPTED_PKEY *enckey = NULL; |
@@ -256,20 +256,20 @@ RSA *d2i_RSA_NET(RSA **a, const unsigned char **pp, long length, | |||
256 | if(!enckey) { | 256 | if(!enckey) { |
257 | ASN1err(ASN1_F_D2I_RSA_NET,ASN1_R_DECODING_ERROR); | 257 | ASN1err(ASN1_F_D2I_RSA_NET,ASN1_R_DECODING_ERROR); |
258 | return NULL; | 258 | return NULL; |
259 | } | 259 | } |
260 | 260 | ||
261 | if ((enckey->os->length != 11) || (strncmp("private-key", | 261 | if ((enckey->os->length != 11) || (strncmp("private-key", |
262 | (char *)enckey->os->data,11) != 0)) | 262 | (char *)enckey->os->data,11) != 0)) |
263 | { | 263 | { |
264 | ASN1err(ASN1_F_D2I_RSA_NET,ASN1_R_PRIVATE_KEY_HEADER_MISSING); | 264 | ASN1err(ASN1_F_D2I_RSA_NET,ASN1_R_PRIVATE_KEY_HEADER_MISSING); |
265 | NETSCAPE_ENCRYPTED_PKEY_free(enckey); | 265 | NETSCAPE_ENCRYPTED_PKEY_free(enckey); |
266 | return NULL; | 266 | return NULL; |
267 | } | 267 | } |
268 | if (OBJ_obj2nid(enckey->enckey->algor->algorithm) != NID_rc4) | 268 | if (OBJ_obj2nid(enckey->enckey->algor->algorithm) != NID_rc4) |
269 | { | 269 | { |
270 | ASN1err(ASN1_F_D2I_RSA_NET,ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM); | 270 | ASN1err(ASN1_F_D2I_RSA_NET,ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM); |
271 | goto err; | 271 | goto err; |
272 | } | 272 | } |
273 | if (cb == NULL) | 273 | if (cb == NULL) |
274 | cb=EVP_read_pw_string; | 274 | cb=EVP_read_pw_string; |
275 | if ((ret=d2i_RSA_NET_2(a, enckey->enckey->digest,cb, sgckey)) == NULL) goto err; | 275 | if ((ret=d2i_RSA_NET_2(a, enckey->enckey->digest,cb, sgckey)) == NULL) goto err; |
@@ -280,12 +280,12 @@ RSA *d2i_RSA_NET(RSA **a, const unsigned char **pp, long length, | |||
280 | NETSCAPE_ENCRYPTED_PKEY_free(enckey); | 280 | NETSCAPE_ENCRYPTED_PKEY_free(enckey); |
281 | return ret; | 281 | return ret; |
282 | 282 | ||
283 | } | 283 | } |
284 | 284 | ||
285 | static RSA *d2i_RSA_NET_2(RSA **a, ASN1_OCTET_STRING *os, | 285 | static RSA *d2i_RSA_NET_2(RSA **a, ASN1_OCTET_STRING *os, |
286 | int (*cb)(char *buf, int len, const char *prompt, | 286 | int (*cb)(char *buf, int len, const char *prompt, |
287 | int verify), int sgckey) | 287 | int verify), int sgckey) |
288 | { | 288 | { |
289 | NETSCAPE_PKEY *pkey=NULL; | 289 | NETSCAPE_PKEY *pkey=NULL; |
290 | RSA *ret=NULL; | 290 | RSA *ret=NULL; |
291 | int i,j; | 291 | int i,j; |
@@ -297,10 +297,10 @@ static RSA *d2i_RSA_NET_2(RSA **a, ASN1_OCTET_STRING *os, | |||
297 | 297 | ||
298 | i=cb((char *)buf,256,"Enter Private Key password:",0); | 298 | i=cb((char *)buf,256,"Enter Private Key password:",0); |
299 | if (i != 0) | 299 | if (i != 0) |
300 | { | 300 | { |
301 | ASN1err(ASN1_F_D2I_RSA_NET_2,ASN1_R_BAD_PASSWORD_READ); | 301 | ASN1err(ASN1_F_D2I_RSA_NET_2,ASN1_R_BAD_PASSWORD_READ); |
302 | goto err; | 302 | goto err; |
303 | } | 303 | } |
304 | 304 | ||
305 | i = strlen((char *)buf); | 305 | i = strlen((char *)buf); |
306 | if(sgckey){ | 306 | if(sgckey){ |
@@ -308,7 +308,7 @@ static RSA *d2i_RSA_NET_2(RSA **a, ASN1_OCTET_STRING *os, | |||
308 | goto err; | 308 | goto err; |
309 | memcpy(buf + 16, "SGCKEYSALT", 10); | 309 | memcpy(buf + 16, "SGCKEYSALT", 10); |
310 | i = 26; | 310 | i = 26; |
311 | } | 311 | } |
312 | 312 | ||
313 | if (!EVP_BytesToKey(EVP_rc4(),EVP_md5(),NULL,buf,i,1,key,NULL)) | 313 | if (!EVP_BytesToKey(EVP_rc4(),EVP_md5(),NULL,buf,i,1,key,NULL)) |
314 | goto err; | 314 | goto err; |
@@ -325,22 +325,22 @@ static RSA *d2i_RSA_NET_2(RSA **a, ASN1_OCTET_STRING *os, | |||
325 | zz=os->data; | 325 | zz=os->data; |
326 | 326 | ||
327 | if ((pkey=d2i_NETSCAPE_PKEY(NULL,&zz,os->length)) == NULL) | 327 | if ((pkey=d2i_NETSCAPE_PKEY(NULL,&zz,os->length)) == NULL) |
328 | { | 328 | { |
329 | ASN1err(ASN1_F_D2I_RSA_NET_2,ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY); | 329 | ASN1err(ASN1_F_D2I_RSA_NET_2,ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY); |
330 | goto err; | 330 | goto err; |
331 | } | 331 | } |
332 | 332 | ||
333 | zz=pkey->private_key->data; | 333 | zz=pkey->private_key->data; |
334 | if ((ret=d2i_RSAPrivateKey(a,&zz,pkey->private_key->length)) == NULL) | 334 | if ((ret=d2i_RSAPrivateKey(a,&zz,pkey->private_key->length)) == NULL) |
335 | { | 335 | { |
336 | ASN1err(ASN1_F_D2I_RSA_NET_2,ASN1_R_UNABLE_TO_DECODE_RSA_KEY); | 336 | ASN1err(ASN1_F_D2I_RSA_NET_2,ASN1_R_UNABLE_TO_DECODE_RSA_KEY); |
337 | goto err; | 337 | goto err; |
338 | } | 338 | } |
339 | err: | 339 | err: |
340 | EVP_CIPHER_CTX_cleanup(&ctx); | 340 | EVP_CIPHER_CTX_cleanup(&ctx); |
341 | NETSCAPE_PKEY_free(pkey); | 341 | NETSCAPE_PKEY_free(pkey); |
342 | return(ret); | 342 | return(ret); |
343 | } | 343 | } |
344 | 344 | ||
345 | #endif /* OPENSSL_NO_RC4 */ | 345 | #endif /* OPENSSL_NO_RC4 */ |
346 | 346 | ||
diff --git a/src/lib/libcrypto/asn1/p5_pbe.c b/src/lib/libcrypto/asn1/p5_pbe.c index 94bc38b99f..f0f23c668d 100644 --- a/src/lib/libcrypto/asn1/p5_pbe.c +++ b/src/lib/libcrypto/asn1/p5_pbe.c | |||
@@ -76,31 +76,31 @@ IMPLEMENT_ASN1_FUNCTIONS(PBEPARAM) | |||
76 | 76 | ||
77 | int PKCS5_pbe_set0_algor(X509_ALGOR *algor, int alg, int iter, | 77 | int PKCS5_pbe_set0_algor(X509_ALGOR *algor, int alg, int iter, |
78 | const unsigned char *salt, int saltlen) | 78 | const unsigned char *salt, int saltlen) |
79 | { | 79 | { |
80 | PBEPARAM *pbe=NULL; | 80 | PBEPARAM *pbe=NULL; |
81 | ASN1_STRING *pbe_str=NULL; | 81 | ASN1_STRING *pbe_str=NULL; |
82 | unsigned char *sstr; | 82 | unsigned char *sstr; |
83 | 83 | ||
84 | pbe = PBEPARAM_new(); | 84 | pbe = PBEPARAM_new(); |
85 | if (!pbe) | 85 | if (!pbe) |
86 | { | 86 | { |
87 | ASN1err(ASN1_F_PKCS5_PBE_SET0_ALGOR,ERR_R_MALLOC_FAILURE); | 87 | ASN1err(ASN1_F_PKCS5_PBE_SET0_ALGOR,ERR_R_MALLOC_FAILURE); |
88 | goto err; | 88 | goto err; |
89 | } | 89 | } |
90 | if(iter <= 0) | 90 | if(iter <= 0) |
91 | iter = PKCS5_DEFAULT_ITER; | 91 | iter = PKCS5_DEFAULT_ITER; |
92 | if (!ASN1_INTEGER_set(pbe->iter, iter)) | 92 | if (!ASN1_INTEGER_set(pbe->iter, iter)) |
93 | { | 93 | { |
94 | ASN1err(ASN1_F_PKCS5_PBE_SET0_ALGOR,ERR_R_MALLOC_FAILURE); | 94 | ASN1err(ASN1_F_PKCS5_PBE_SET0_ALGOR,ERR_R_MALLOC_FAILURE); |
95 | goto err; | 95 | goto err; |
96 | } | 96 | } |
97 | if (!saltlen) | 97 | if (!saltlen) |
98 | saltlen = PKCS5_SALT_LEN; | 98 | saltlen = PKCS5_SALT_LEN; |
99 | if (!ASN1_STRING_set(pbe->salt, NULL, saltlen)) | 99 | if (!ASN1_STRING_set(pbe->salt, NULL, saltlen)) |
100 | { | 100 | { |
101 | ASN1err(ASN1_F_PKCS5_PBE_SET0_ALGOR,ERR_R_MALLOC_FAILURE); | 101 | ASN1err(ASN1_F_PKCS5_PBE_SET0_ALGOR,ERR_R_MALLOC_FAILURE); |
102 | goto err; | 102 | goto err; |
103 | } | 103 | } |
104 | sstr = ASN1_STRING_data(pbe->salt); | 104 | sstr = ASN1_STRING_data(pbe->salt); |
105 | if (salt) | 105 | if (salt) |
106 | memcpy(sstr, salt, saltlen); | 106 | memcpy(sstr, salt, saltlen); |
@@ -108,10 +108,10 @@ int PKCS5_pbe_set0_algor(X509_ALGOR *algor, int alg, int iter, | |||
108 | goto err; | 108 | goto err; |
109 | 109 | ||
110 | if(!ASN1_item_pack(pbe, ASN1_ITEM_rptr(PBEPARAM), &pbe_str)) | 110 | if(!ASN1_item_pack(pbe, ASN1_ITEM_rptr(PBEPARAM), &pbe_str)) |
111 | { | 111 | { |
112 | ASN1err(ASN1_F_PKCS5_PBE_SET0_ALGOR,ERR_R_MALLOC_FAILURE); | 112 | ASN1err(ASN1_F_PKCS5_PBE_SET0_ALGOR,ERR_R_MALLOC_FAILURE); |
113 | goto err; | 113 | goto err; |
114 | } | 114 | } |
115 | 115 | ||
116 | PBEPARAM_free(pbe); | 116 | PBEPARAM_free(pbe); |
117 | pbe = NULL; | 117 | pbe = NULL; |
@@ -125,24 +125,24 @@ err: | |||
125 | if (pbe_str != NULL) | 125 | if (pbe_str != NULL) |
126 | ASN1_STRING_free(pbe_str); | 126 | ASN1_STRING_free(pbe_str); |
127 | return 0; | 127 | return 0; |
128 | } | 128 | } |
129 | 129 | ||
130 | /* Return an algorithm identifier for a PKCS#5 PBE algorithm */ | 130 | /* Return an algorithm identifier for a PKCS#5 PBE algorithm */ |
131 | 131 | ||
132 | X509_ALGOR *PKCS5_pbe_set(int alg, int iter, | 132 | X509_ALGOR *PKCS5_pbe_set(int alg, int iter, |
133 | const unsigned char *salt, int saltlen) | 133 | const unsigned char *salt, int saltlen) |
134 | { | 134 | { |
135 | X509_ALGOR *ret; | 135 | X509_ALGOR *ret; |
136 | ret = X509_ALGOR_new(); | 136 | ret = X509_ALGOR_new(); |
137 | if (!ret) | 137 | if (!ret) |
138 | { | 138 | { |
139 | ASN1err(ASN1_F_PKCS5_PBE_SET,ERR_R_MALLOC_FAILURE); | 139 | ASN1err(ASN1_F_PKCS5_PBE_SET,ERR_R_MALLOC_FAILURE); |
140 | return NULL; | 140 | return NULL; |
141 | } | 141 | } |
142 | 142 | ||
143 | if (PKCS5_pbe_set0_algor(ret, alg, iter, salt, saltlen)) | 143 | if (PKCS5_pbe_set0_algor(ret, alg, iter, salt, saltlen)) |
144 | return ret; | 144 | return ret; |
145 | 145 | ||
146 | X509_ALGOR_free(ret); | 146 | X509_ALGOR_free(ret); |
147 | return NULL; | 147 | return NULL; |
148 | } | 148 | } |
diff --git a/src/lib/libcrypto/asn1/p8_pkey.c b/src/lib/libcrypto/asn1/p8_pkey.c index 17b68d386d..9d26cf51ec 100644 --- a/src/lib/libcrypto/asn1/p8_pkey.c +++ b/src/lib/libcrypto/asn1/p8_pkey.c | |||
@@ -71,7 +71,7 @@ static int pkey_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, | |||
71 | if (key->pkey->value.octet_string) | 71 | if (key->pkey->value.octet_string) |
72 | OPENSSL_cleanse(key->pkey->value.octet_string->data, | 72 | OPENSSL_cleanse(key->pkey->value.octet_string->data, |
73 | key->pkey->value.octet_string->length); | 73 | key->pkey->value.octet_string->length); |
74 | } | 74 | } |
75 | return 1; | 75 | return 1; |
76 | } | 76 | } |
77 | 77 | ||
@@ -88,15 +88,15 @@ int PKCS8_pkey_set0(PKCS8_PRIV_KEY_INFO *priv, ASN1_OBJECT *aobj, | |||
88 | int version, | 88 | int version, |
89 | int ptype, void *pval, | 89 | int ptype, void *pval, |
90 | unsigned char *penc, int penclen) | 90 | unsigned char *penc, int penclen) |
91 | { | 91 | { |
92 | unsigned char **ppenc = NULL; | 92 | unsigned char **ppenc = NULL; |
93 | if (version >= 0) | 93 | if (version >= 0) |
94 | { | 94 | { |
95 | if (!ASN1_INTEGER_set(priv->version, version)) | 95 | if (!ASN1_INTEGER_set(priv->version, version)) |
96 | return 0; | 96 | return 0; |
97 | } | 97 | } |
98 | if (penc) | 98 | if (penc) |
99 | { | 99 | { |
100 | int pmtype; | 100 | int pmtype; |
101 | ASN1_OCTET_STRING *oct; | 101 | ASN1_OCTET_STRING *oct; |
102 | oct = ASN1_OCTET_STRING_new(); | 102 | oct = ASN1_OCTET_STRING_new(); |
@@ -110,46 +110,46 @@ int PKCS8_pkey_set0(PKCS8_PRIV_KEY_INFO *priv, ASN1_OBJECT *aobj, | |||
110 | else | 110 | else |
111 | pmtype = V_ASN1_OCTET_STRING; | 111 | pmtype = V_ASN1_OCTET_STRING; |
112 | ASN1_TYPE_set(priv->pkey, pmtype, oct); | 112 | ASN1_TYPE_set(priv->pkey, pmtype, oct); |
113 | } | 113 | } |
114 | if (!X509_ALGOR_set0(priv->pkeyalg, aobj, ptype, pval)) | 114 | if (!X509_ALGOR_set0(priv->pkeyalg, aobj, ptype, pval)) |
115 | { | 115 | { |
116 | /* If call fails do not swallow 'enc' */ | 116 | /* If call fails do not swallow 'enc' */ |
117 | if (ppenc) | 117 | if (ppenc) |
118 | *ppenc = NULL; | 118 | *ppenc = NULL; |
119 | return 0; | 119 | return 0; |
120 | } | ||
121 | return 1; | ||
122 | } | 120 | } |
121 | return 1; | ||
122 | } | ||
123 | 123 | ||
124 | int PKCS8_pkey_get0(ASN1_OBJECT **ppkalg, | 124 | int PKCS8_pkey_get0(ASN1_OBJECT **ppkalg, |
125 | const unsigned char **pk, int *ppklen, | 125 | const unsigned char **pk, int *ppklen, |
126 | X509_ALGOR **pa, | 126 | X509_ALGOR **pa, |
127 | PKCS8_PRIV_KEY_INFO *p8) | 127 | PKCS8_PRIV_KEY_INFO *p8) |
128 | { | 128 | { |
129 | if (ppkalg) | 129 | if (ppkalg) |
130 | *ppkalg = p8->pkeyalg->algorithm; | 130 | *ppkalg = p8->pkeyalg->algorithm; |
131 | if(p8->pkey->type == V_ASN1_OCTET_STRING) | 131 | if(p8->pkey->type == V_ASN1_OCTET_STRING) |
132 | { | 132 | { |
133 | p8->broken = PKCS8_OK; | 133 | p8->broken = PKCS8_OK; |
134 | if (pk) | 134 | if (pk) |
135 | { | 135 | { |
136 | *pk = p8->pkey->value.octet_string->data; | 136 | *pk = p8->pkey->value.octet_string->data; |
137 | *ppklen = p8->pkey->value.octet_string->length; | 137 | *ppklen = p8->pkey->value.octet_string->length; |
138 | } | ||
139 | } | 138 | } |
139 | } | ||
140 | else if (p8->pkey->type == V_ASN1_SEQUENCE) | 140 | else if (p8->pkey->type == V_ASN1_SEQUENCE) |
141 | { | 141 | { |
142 | p8->broken = PKCS8_NO_OCTET; | 142 | p8->broken = PKCS8_NO_OCTET; |
143 | if (pk) | 143 | if (pk) |
144 | { | 144 | { |
145 | *pk = p8->pkey->value.sequence->data; | 145 | *pk = p8->pkey->value.sequence->data; |
146 | *ppklen = p8->pkey->value.sequence->length; | 146 | *ppklen = p8->pkey->value.sequence->length; |
147 | } | ||
148 | } | 147 | } |
148 | } | ||
149 | else | 149 | else |
150 | return 0; | 150 | return 0; |
151 | if (pa) | 151 | if (pa) |
152 | *pa = p8->pkeyalg; | 152 | *pa = p8->pkeyalg; |
153 | return 1; | 153 | return 1; |
154 | } | 154 | } |
155 | 155 | ||
diff --git a/src/lib/libcrypto/asn1/t_crl.c b/src/lib/libcrypto/asn1/t_crl.c index f6550b2b04..1624cc5fcc 100644 --- a/src/lib/libcrypto/asn1/t_crl.c +++ b/src/lib/libcrypto/asn1/t_crl.c | |||
@@ -66,20 +66,20 @@ | |||
66 | 66 | ||
67 | #ifndef OPENSSL_NO_FP_API | 67 | #ifndef OPENSSL_NO_FP_API |
68 | int X509_CRL_print_fp(FILE *fp, X509_CRL *x) | 68 | int X509_CRL_print_fp(FILE *fp, X509_CRL *x) |
69 | { | 69 | { |
70 | BIO *b; | 70 | BIO *b; |
71 | int ret; | 71 | int ret; |
72 | 72 | ||
73 | if ((b=BIO_new(BIO_s_file())) == NULL) | 73 | if ((b=BIO_new(BIO_s_file())) == NULL) |
74 | { | 74 | { |
75 | X509err(X509_F_X509_CRL_PRINT_FP,ERR_R_BUF_LIB); | 75 | X509err(X509_F_X509_CRL_PRINT_FP,ERR_R_BUF_LIB); |
76 | return(0); | 76 | return(0); |
77 | } | 77 | } |
78 | BIO_set_fp(b,fp,BIO_NOCLOSE); | 78 | BIO_set_fp(b,fp,BIO_NOCLOSE); |
79 | ret=X509_CRL_print(b, x); | 79 | ret=X509_CRL_print(b, x); |
80 | BIO_free(b); | 80 | BIO_free(b); |
81 | return(ret); | 81 | return(ret); |
82 | } | 82 | } |
83 | #endif | 83 | #endif |
84 | 84 | ||
85 | int X509_CRL_print(BIO *out, X509_CRL *x) | 85 | int X509_CRL_print(BIO *out, X509_CRL *x) |
diff --git a/src/lib/libcrypto/asn1/t_pkey.c b/src/lib/libcrypto/asn1/t_pkey.c index 9dd18f6579..61f5cd61f1 100644 --- a/src/lib/libcrypto/asn1/t_pkey.c +++ b/src/lib/libcrypto/asn1/t_pkey.c | |||
@@ -64,7 +64,7 @@ | |||
64 | 64 | ||
65 | int ASN1_bn_print(BIO *bp, const char *number, const BIGNUM *num, | 65 | int ASN1_bn_print(BIO *bp, const char *number, const BIGNUM *num, |
66 | unsigned char *buf, int off) | 66 | unsigned char *buf, int off) |
67 | { | 67 | { |
68 | int n,i; | 68 | int n,i; |
69 | const char *neg; | 69 | const char *neg; |
70 | 70 | ||
@@ -73,20 +73,20 @@ int ASN1_bn_print(BIO *bp, const char *number, const BIGNUM *num, | |||
73 | if(!BIO_indent(bp,off,128)) | 73 | if(!BIO_indent(bp,off,128)) |
74 | return 0; | 74 | return 0; |
75 | if (BN_is_zero(num)) | 75 | if (BN_is_zero(num)) |
76 | { | 76 | { |
77 | if (BIO_printf(bp, "%s 0\n", number) <= 0) | 77 | if (BIO_printf(bp, "%s 0\n", number) <= 0) |
78 | return 0; | 78 | return 0; |
79 | return 1; | 79 | return 1; |
80 | } | 80 | } |
81 | 81 | ||
82 | if (BN_num_bytes(num) <= BN_BYTES) | 82 | if (BN_num_bytes(num) <= BN_BYTES) |
83 | { | 83 | { |
84 | if (BIO_printf(bp,"%s %s%lu (%s0x%lx)\n",number,neg, | 84 | if (BIO_printf(bp,"%s %s%lu (%s0x%lx)\n",number,neg, |
85 | (unsigned long)num->d[0],neg,(unsigned long)num->d[0]) | 85 | (unsigned long)num->d[0],neg,(unsigned long)num->d[0]) |
86 | <= 0) return(0); | 86 | <= 0) return(0); |
87 | } | 87 | } |
88 | else | 88 | else |
89 | { | 89 | { |
90 | buf[0]=0; | 90 | buf[0]=0; |
91 | if (BIO_printf(bp,"%s%s",number, | 91 | if (BIO_printf(bp,"%s%s",number, |
92 | (neg[0] == '-')?" (Negative)":"") <= 0) | 92 | (neg[0] == '-')?" (Negative)":"") <= 0) |
@@ -98,17 +98,17 @@ int ASN1_bn_print(BIO *bp, const char *number, const BIGNUM *num, | |||
98 | else buf++; | 98 | else buf++; |
99 | 99 | ||
100 | for (i=0; i<n; i++) | 100 | for (i=0; i<n; i++) |
101 | { | 101 | { |
102 | if ((i%15) == 0) | 102 | if ((i%15) == 0) |
103 | { | 103 | { |
104 | if(BIO_puts(bp,"\n") <= 0 | 104 | if(BIO_puts(bp,"\n") <= 0 |
105 | || !BIO_indent(bp,off+4,128)) | 105 | || !BIO_indent(bp,off+4,128)) |
106 | return 0; | 106 | return 0; |
107 | } | 107 | } |
108 | if (BIO_printf(bp,"%02x%s",buf[i],((i+1) == n)?"":":") | 108 | if (BIO_printf(bp,"%02x%s",buf[i],((i+1) == n)?"":":") |
109 | <= 0) return(0); | 109 | <= 0) return(0); |
110 | } | ||
111 | if (BIO_write(bp,"\n",1) <= 0) return(0); | ||
112 | } | 110 | } |
113 | return(1); | 111 | if (BIO_write(bp,"\n",1) <= 0) return(0); |
114 | } | 112 | } |
113 | return(1); | ||
114 | } | ||
diff --git a/src/lib/libcrypto/asn1/t_req.c b/src/lib/libcrypto/asn1/t_req.c index ea1794e3e0..a863543898 100644 --- a/src/lib/libcrypto/asn1/t_req.c +++ b/src/lib/libcrypto/asn1/t_req.c | |||
@@ -72,24 +72,24 @@ | |||
72 | 72 | ||
73 | #ifndef OPENSSL_NO_FP_API | 73 | #ifndef OPENSSL_NO_FP_API |
74 | int X509_REQ_print_fp(FILE *fp, X509_REQ *x) | 74 | int X509_REQ_print_fp(FILE *fp, X509_REQ *x) |
75 | { | 75 | { |
76 | BIO *b; | 76 | BIO *b; |
77 | int ret; | 77 | int ret; |
78 | 78 | ||
79 | if ((b=BIO_new(BIO_s_file())) == NULL) | 79 | if ((b=BIO_new(BIO_s_file())) == NULL) |
80 | { | 80 | { |
81 | X509err(X509_F_X509_REQ_PRINT_FP,ERR_R_BUF_LIB); | 81 | X509err(X509_F_X509_REQ_PRINT_FP,ERR_R_BUF_LIB); |
82 | return(0); | 82 | return(0); |
83 | } | 83 | } |
84 | BIO_set_fp(b,fp,BIO_NOCLOSE); | 84 | BIO_set_fp(b,fp,BIO_NOCLOSE); |
85 | ret=X509_REQ_print(b, x); | 85 | ret=X509_REQ_print(b, x); |
86 | BIO_free(b); | 86 | BIO_free(b); |
87 | return(ret); | 87 | return(ret); |
88 | } | 88 | } |
89 | #endif | 89 | #endif |
90 | 90 | ||
91 | int X509_REQ_print_ex(BIO *bp, X509_REQ *x, unsigned long nmflags, unsigned long cflag) | 91 | int X509_REQ_print_ex(BIO *bp, X509_REQ *x, unsigned long nmflags, unsigned long cflag) |
92 | { | 92 | { |
93 | unsigned long l; | 93 | unsigned long l; |
94 | int i; | 94 | int i; |
95 | const char *neg; | 95 | const char *neg; |
@@ -111,20 +111,20 @@ int X509_REQ_print_ex(BIO *bp, X509_REQ *x, unsigned long nmflags, unsigned long | |||
111 | 111 | ||
112 | ri=x->req_info; | 112 | ri=x->req_info; |
113 | if(!(cflag & X509_FLAG_NO_HEADER)) | 113 | if(!(cflag & X509_FLAG_NO_HEADER)) |
114 | { | 114 | { |
115 | if (BIO_write(bp,"Certificate Request:\n",21) <= 0) goto err; | 115 | if (BIO_write(bp,"Certificate Request:\n",21) <= 0) goto err; |
116 | if (BIO_write(bp," Data:\n",10) <= 0) goto err; | 116 | if (BIO_write(bp," Data:\n",10) <= 0) goto err; |
117 | } | 117 | } |
118 | if(!(cflag & X509_FLAG_NO_VERSION)) | 118 | if(!(cflag & X509_FLAG_NO_VERSION)) |
119 | { | 119 | { |
120 | neg=(ri->version->type == V_ASN1_NEG_INTEGER)?"-":""; | 120 | neg=(ri->version->type == V_ASN1_NEG_INTEGER)?"-":""; |
121 | l=0; | 121 | l=0; |
122 | for (i=0; i<ri->version->length; i++) | 122 | for (i=0; i<ri->version->length; i++) |
123 | { l<<=8; l+=ri->version->data[i]; } | 123 | { l<<=8; l+=ri->version->data[i]; } |
124 | if(BIO_printf(bp,"%8sVersion: %s%lu (%s0x%lx)\n","",neg,l,neg, | 124 | if(BIO_printf(bp,"%8sVersion: %s%lu (%s0x%lx)\n","",neg,l,neg, |
125 | l) <= 0) | 125 | l) <= 0) |
126 | goto err; | 126 | goto err; |
127 | } | 127 | } |
128 | if(!(cflag & X509_FLAG_NO_SUBJECT)) | 128 | if(!(cflag & X509_FLAG_NO_SUBJECT)) |
129 | { | 129 | { |
130 | if (BIO_printf(bp," Subject:%c",mlch) <= 0) goto err; | 130 | if (BIO_printf(bp," Subject:%c",mlch) <= 0) goto err; |
@@ -132,7 +132,7 @@ int X509_REQ_print_ex(BIO *bp, X509_REQ *x, unsigned long nmflags, unsigned long | |||
132 | if (BIO_write(bp,"\n",1) <= 0) goto err; | 132 | if (BIO_write(bp,"\n",1) <= 0) goto err; |
133 | } | 133 | } |
134 | if(!(cflag & X509_FLAG_NO_PUBKEY)) | 134 | if(!(cflag & X509_FLAG_NO_PUBKEY)) |
135 | { | 135 | { |
136 | if (BIO_write(bp," Subject Public Key Info:\n",33) <= 0) | 136 | if (BIO_write(bp," Subject Public Key Info:\n",33) <= 0) |
137 | goto err; | 137 | goto err; |
138 | if (BIO_printf(bp,"%12sPublic Key Algorithm: ","") <= 0) | 138 | if (BIO_printf(bp,"%12sPublic Key Algorithm: ","") <= 0) |
@@ -144,33 +144,33 @@ int X509_REQ_print_ex(BIO *bp, X509_REQ *x, unsigned long nmflags, unsigned long | |||
144 | 144 | ||
145 | pkey=X509_REQ_get_pubkey(x); | 145 | pkey=X509_REQ_get_pubkey(x); |
146 | if (pkey == NULL) | 146 | if (pkey == NULL) |
147 | { | 147 | { |
148 | BIO_printf(bp,"%12sUnable to load Public Key\n",""); | 148 | BIO_printf(bp,"%12sUnable to load Public Key\n",""); |
149 | ERR_print_errors(bp); | 149 | ERR_print_errors(bp); |
150 | } | 150 | } |
151 | else | 151 | else |
152 | { | 152 | { |
153 | EVP_PKEY_print_public(bp, pkey, 16, NULL); | 153 | EVP_PKEY_print_public(bp, pkey, 16, NULL); |
154 | EVP_PKEY_free(pkey); | 154 | EVP_PKEY_free(pkey); |
155 | } | ||
156 | } | 155 | } |
156 | } | ||
157 | 157 | ||
158 | if(!(cflag & X509_FLAG_NO_ATTRIBUTES)) | 158 | if(!(cflag & X509_FLAG_NO_ATTRIBUTES)) |
159 | { | 159 | { |
160 | /* may not be */ | 160 | /* may not be */ |
161 | if(BIO_printf(bp,"%8sAttributes:\n","") <= 0) | 161 | if(BIO_printf(bp,"%8sAttributes:\n","") <= 0) |
162 | goto err; | 162 | goto err; |
163 | 163 | ||
164 | sk=x->req_info->attributes; | 164 | sk=x->req_info->attributes; |
165 | if (sk_X509_ATTRIBUTE_num(sk) == 0) | 165 | if (sk_X509_ATTRIBUTE_num(sk) == 0) |
166 | { | 166 | { |
167 | if(BIO_printf(bp,"%12sa0:00\n","") <= 0) | 167 | if(BIO_printf(bp,"%12sa0:00\n","") <= 0) |
168 | goto err; | 168 | goto err; |
169 | } | 169 | } |
170 | else | 170 | else |
171 | { | 171 | { |
172 | for (i=0; i<sk_X509_ATTRIBUTE_num(sk); i++) | 172 | for (i=0; i<sk_X509_ATTRIBUTE_num(sk); i++) |
173 | { | 173 | { |
174 | ASN1_TYPE *at; | 174 | ASN1_TYPE *at; |
175 | X509_ATTRIBUTE *a; | 175 | X509_ATTRIBUTE *a; |
176 | ASN1_BIT_STRING *bs=NULL; | 176 | ASN1_BIT_STRING *bs=NULL; |
@@ -183,51 +183,51 @@ int X509_REQ_print_ex(BIO *bp, X509_REQ *x, unsigned long nmflags, unsigned long | |||
183 | if(BIO_printf(bp,"%12s","") <= 0) | 183 | if(BIO_printf(bp,"%12s","") <= 0) |
184 | goto err; | 184 | goto err; |
185 | if ((j=i2a_ASN1_OBJECT(bp,a->object)) > 0) | 185 | if ((j=i2a_ASN1_OBJECT(bp,a->object)) > 0) |
186 | { | 186 | { |
187 | if (a->single) | 187 | if (a->single) |
188 | { | 188 | { |
189 | t=a->value.single; | 189 | t=a->value.single; |
190 | type=t->type; | 190 | type=t->type; |
191 | bs=t->value.bit_string; | 191 | bs=t->value.bit_string; |
192 | } | 192 | } |
193 | else | 193 | else |
194 | { | 194 | { |
195 | ii=0; | 195 | ii=0; |
196 | count=sk_ASN1_TYPE_num(a->value.set); | 196 | count=sk_ASN1_TYPE_num(a->value.set); |
197 | get_next: | 197 | get_next: |
198 | at=sk_ASN1_TYPE_value(a->value.set,ii); | 198 | at=sk_ASN1_TYPE_value(a->value.set,ii); |
199 | type=at->type; | 199 | type=at->type; |
200 | bs=at->value.asn1_string; | 200 | bs=at->value.asn1_string; |
201 | } | ||
202 | } | 201 | } |
202 | } | ||
203 | for (j=25-j; j>0; j--) | 203 | for (j=25-j; j>0; j--) |
204 | if (BIO_write(bp," ",1) != 1) goto err; | 204 | if (BIO_write(bp," ",1) != 1) goto err; |
205 | if (BIO_puts(bp,":") <= 0) goto err; | 205 | if (BIO_puts(bp,":") <= 0) goto err; |
206 | if ( (type == V_ASN1_PRINTABLESTRING) || | 206 | if ( (type == V_ASN1_PRINTABLESTRING) || |
207 | (type == V_ASN1_T61STRING) || | 207 | (type == V_ASN1_T61STRING) || |
208 | (type == V_ASN1_IA5STRING)) | 208 | (type == V_ASN1_IA5STRING)) |
209 | { | 209 | { |
210 | if (BIO_write(bp,(char *)bs->data,bs->length) | 210 | if (BIO_write(bp,(char *)bs->data,bs->length) |
211 | != bs->length) | 211 | != bs->length) |
212 | goto err; | 212 | goto err; |
213 | BIO_puts(bp,"\n"); | 213 | BIO_puts(bp,"\n"); |
214 | } | 214 | } |
215 | else | 215 | else |
216 | { | 216 | { |
217 | BIO_puts(bp,"unable to print attribute\n"); | 217 | BIO_puts(bp,"unable to print attribute\n"); |
218 | } | ||
219 | if (++ii < count) goto get_next; | ||
220 | } | 218 | } |
219 | if (++ii < count) goto get_next; | ||
221 | } | 220 | } |
222 | } | 221 | } |
222 | } | ||
223 | if(!(cflag & X509_FLAG_NO_EXTENSIONS)) | 223 | if(!(cflag & X509_FLAG_NO_EXTENSIONS)) |
224 | { | 224 | { |
225 | exts = X509_REQ_get_extensions(x); | 225 | exts = X509_REQ_get_extensions(x); |
226 | if(exts) | 226 | if(exts) |
227 | { | 227 | { |
228 | BIO_printf(bp,"%8sRequested Extensions:\n",""); | 228 | BIO_printf(bp,"%8sRequested Extensions:\n",""); |
229 | for (i=0; i<sk_X509_EXTENSION_num(exts); i++) | 229 | for (i=0; i<sk_X509_EXTENSION_num(exts); i++) |
230 | { | 230 | { |
231 | ASN1_OBJECT *obj; | 231 | ASN1_OBJECT *obj; |
232 | X509_EXTENSION *ex; | 232 | X509_EXTENSION *ex; |
233 | int j; | 233 | int j; |
@@ -239,28 +239,28 @@ get_next: | |||
239 | if (BIO_printf(bp,": %s\n",j?"critical":"") <= 0) | 239 | if (BIO_printf(bp,": %s\n",j?"critical":"") <= 0) |
240 | goto err; | 240 | goto err; |
241 | if(!X509V3_EXT_print(bp, ex, cflag, 16)) | 241 | if(!X509V3_EXT_print(bp, ex, cflag, 16)) |
242 | { | 242 | { |
243 | BIO_printf(bp, "%16s", ""); | 243 | BIO_printf(bp, "%16s", ""); |
244 | M_ASN1_OCTET_STRING_print(bp,ex->value); | 244 | M_ASN1_OCTET_STRING_print(bp,ex->value); |
245 | } | ||
246 | if (BIO_write(bp,"\n",1) <= 0) goto err; | ||
247 | } | 245 | } |
248 | sk_X509_EXTENSION_pop_free(exts, X509_EXTENSION_free); | 246 | if (BIO_write(bp,"\n",1) <= 0) goto err; |
249 | } | 247 | } |
248 | sk_X509_EXTENSION_pop_free(exts, X509_EXTENSION_free); | ||
250 | } | 249 | } |
250 | } | ||
251 | 251 | ||
252 | if(!(cflag & X509_FLAG_NO_SIGDUMP)) | 252 | if(!(cflag & X509_FLAG_NO_SIGDUMP)) |
253 | { | 253 | { |
254 | if(!X509_signature_print(bp, x->sig_alg, x->signature)) goto err; | 254 | if(!X509_signature_print(bp, x->sig_alg, x->signature)) goto err; |
255 | } | 255 | } |
256 | 256 | ||
257 | return(1); | 257 | return(1); |
258 | err: | 258 | err: |
259 | X509err(X509_F_X509_REQ_PRINT_EX,ERR_R_BUF_LIB); | 259 | X509err(X509_F_X509_REQ_PRINT_EX,ERR_R_BUF_LIB); |
260 | return(0); | 260 | return(0); |
261 | } | 261 | } |
262 | 262 | ||
263 | int X509_REQ_print(BIO *bp, X509_REQ *x) | 263 | int X509_REQ_print(BIO *bp, X509_REQ *x) |
264 | { | 264 | { |
265 | return X509_REQ_print_ex(bp, x, XN_FLAG_COMPAT, X509_FLAG_COMPAT); | 265 | return X509_REQ_print_ex(bp, x, XN_FLAG_COMPAT, X509_FLAG_COMPAT); |
266 | } | 266 | } |
diff --git a/src/lib/libcrypto/asn1/t_spki.c b/src/lib/libcrypto/asn1/t_spki.c index 079c081a81..016eb2fc2e 100644 --- a/src/lib/libcrypto/asn1/t_spki.c +++ b/src/lib/libcrypto/asn1/t_spki.c | |||
@@ -83,10 +83,10 @@ int NETSCAPE_SPKI_print(BIO *out, NETSCAPE_SPKI *spki) | |||
83 | pkey = X509_PUBKEY_get(spki->spkac->pubkey); | 83 | pkey = X509_PUBKEY_get(spki->spkac->pubkey); |
84 | if(!pkey) BIO_printf(out, " Unable to load public key\n"); | 84 | if(!pkey) BIO_printf(out, " Unable to load public key\n"); |
85 | else | 85 | else |
86 | { | 86 | { |
87 | EVP_PKEY_print_public(out, pkey, 4, NULL); | 87 | EVP_PKEY_print_public(out, pkey, 4, NULL); |
88 | EVP_PKEY_free(pkey); | 88 | EVP_PKEY_free(pkey); |
89 | } | 89 | } |
90 | chal = spki->spkac->challenge; | 90 | chal = spki->spkac->challenge; |
91 | if(chal->length) | 91 | if(chal->length) |
92 | BIO_printf(out, " Challenge String: %s\n", chal->data); | 92 | BIO_printf(out, " Challenge String: %s\n", chal->data); |
@@ -97,11 +97,11 @@ int NETSCAPE_SPKI_print(BIO *out, NETSCAPE_SPKI *spki) | |||
97 | n=spki->signature->length; | 97 | n=spki->signature->length; |
98 | s=(char *)spki->signature->data; | 98 | s=(char *)spki->signature->data; |
99 | for (i=0; i<n; i++) | 99 | for (i=0; i<n; i++) |
100 | { | 100 | { |
101 | if ((i%18) == 0) BIO_write(out,"\n ",7); | 101 | if ((i%18) == 0) BIO_write(out,"\n ",7); |
102 | BIO_printf(out,"%02x%s",(unsigned char)s[i], | 102 | BIO_printf(out,"%02x%s",(unsigned char)s[i], |
103 | ((i+1) == n)?"":":"); | 103 | ((i+1) == n)?"":":"); |
104 | } | 104 | } |
105 | BIO_write(out,"\n",1); | 105 | BIO_write(out,"\n",1); |
106 | return 1; | 106 | return 1; |
107 | } | 107 | } |
diff --git a/src/lib/libcrypto/asn1/t_x509.c b/src/lib/libcrypto/asn1/t_x509.c index 8dfda07b92..30d49cc4dd 100644 --- a/src/lib/libcrypto/asn1/t_x509.c +++ b/src/lib/libcrypto/asn1/t_x509.c | |||
@@ -76,9 +76,9 @@ | |||
76 | 76 | ||
77 | #ifndef OPENSSL_NO_FP_API | 77 | #ifndef OPENSSL_NO_FP_API |
78 | int X509_print_fp(FILE *fp, X509 *x) | 78 | int X509_print_fp(FILE *fp, X509 *x) |
79 | { | 79 | { |
80 | return X509_print_ex_fp(fp, x, XN_FLAG_COMPAT, X509_FLAG_COMPAT); | 80 | return X509_print_ex_fp(fp, x, XN_FLAG_COMPAT, X509_FLAG_COMPAT); |
81 | } | 81 | } |
82 | 82 | ||
83 | int X509_print_ex_fp(FILE *fp, X509 *x, unsigned long nmflag, unsigned long cflag) | 83 | int X509_print_ex_fp(FILE *fp, X509 *x, unsigned long nmflag, unsigned long cflag) |
84 | { | 84 | { |
@@ -86,10 +86,10 @@ int X509_print_ex_fp(FILE *fp, X509 *x, unsigned long nmflag, unsigned long cfla | |||
86 | int ret; | 86 | int ret; |
87 | 87 | ||
88 | if ((b=BIO_new(BIO_s_file())) == NULL) | 88 | if ((b=BIO_new(BIO_s_file())) == NULL) |
89 | { | 89 | { |
90 | X509err(X509_F_X509_PRINT_EX_FP,ERR_R_BUF_LIB); | 90 | X509err(X509_F_X509_PRINT_EX_FP,ERR_R_BUF_LIB); |
91 | return(0); | 91 | return(0); |
92 | } | 92 | } |
93 | BIO_set_fp(b,fp,BIO_NOCLOSE); | 93 | BIO_set_fp(b,fp,BIO_NOCLOSE); |
94 | ret=X509_print_ex(b, x, nmflag, cflag); | 94 | ret=X509_print_ex(b, x, nmflag, cflag); |
95 | BIO_free(b); | 95 | BIO_free(b); |
@@ -103,7 +103,7 @@ int X509_print(BIO *bp, X509 *x) | |||
103 | } | 103 | } |
104 | 104 | ||
105 | int X509_print_ex(BIO *bp, X509 *x, unsigned long nmflags, unsigned long cflag) | 105 | int X509_print_ex(BIO *bp, X509 *x, unsigned long nmflags, unsigned long cflag) |
106 | { | 106 | { |
107 | long l; | 107 | long l; |
108 | int ret=0,i; | 108 | int ret=0,i; |
109 | char *m=NULL,mlch = ' '; | 109 | char *m=NULL,mlch = ' '; |
@@ -123,51 +123,51 @@ int X509_print_ex(BIO *bp, X509 *x, unsigned long nmflags, unsigned long cflag) | |||
123 | 123 | ||
124 | ci=x->cert_info; | 124 | ci=x->cert_info; |
125 | if(!(cflag & X509_FLAG_NO_HEADER)) | 125 | if(!(cflag & X509_FLAG_NO_HEADER)) |
126 | { | 126 | { |
127 | if (BIO_write(bp,"Certificate:\n",13) <= 0) goto err; | 127 | if (BIO_write(bp,"Certificate:\n",13) <= 0) goto err; |
128 | if (BIO_write(bp," Data:\n",10) <= 0) goto err; | 128 | if (BIO_write(bp," Data:\n",10) <= 0) goto err; |
129 | } | 129 | } |
130 | if(!(cflag & X509_FLAG_NO_VERSION)) | 130 | if(!(cflag & X509_FLAG_NO_VERSION)) |
131 | { | 131 | { |
132 | l=X509_get_version(x); | 132 | l=X509_get_version(x); |
133 | if (BIO_printf(bp,"%8sVersion: %lu (0x%lx)\n","",l+1,l) <= 0) goto err; | 133 | if (BIO_printf(bp,"%8sVersion: %lu (0x%lx)\n","",l+1,l) <= 0) goto err; |
134 | } | 134 | } |
135 | if(!(cflag & X509_FLAG_NO_SERIAL)) | 135 | if(!(cflag & X509_FLAG_NO_SERIAL)) |
136 | { | 136 | { |
137 | 137 | ||
138 | if (BIO_write(bp," Serial Number:",22) <= 0) goto err; | 138 | if (BIO_write(bp," Serial Number:",22) <= 0) goto err; |
139 | 139 | ||
140 | bs=X509_get_serialNumber(x); | 140 | bs=X509_get_serialNumber(x); |
141 | if (bs->length <= (int)sizeof(long)) | 141 | if (bs->length <= (int)sizeof(long)) |
142 | { | 142 | { |
143 | l=ASN1_INTEGER_get(bs); | 143 | l=ASN1_INTEGER_get(bs); |
144 | if (bs->type == V_ASN1_NEG_INTEGER) | 144 | if (bs->type == V_ASN1_NEG_INTEGER) |
145 | { | 145 | { |
146 | l= -l; | 146 | l= -l; |
147 | neg="-"; | 147 | neg="-"; |
148 | } | 148 | } |
149 | else | 149 | else |
150 | neg=""; | 150 | neg=""; |
151 | if (BIO_printf(bp," %s%lu (%s0x%lx)\n",neg,l,neg,l) <= 0) | 151 | if (BIO_printf(bp," %s%lu (%s0x%lx)\n",neg,l,neg,l) <= 0) |
152 | goto err; | 152 | goto err; |
153 | } | 153 | } |
154 | else | 154 | else |
155 | { | 155 | { |
156 | neg=(bs->type == V_ASN1_NEG_INTEGER)?" (Negative)":""; | 156 | neg=(bs->type == V_ASN1_NEG_INTEGER)?" (Negative)":""; |
157 | if (BIO_printf(bp,"\n%12s%s","",neg) <= 0) goto err; | 157 | if (BIO_printf(bp,"\n%12s%s","",neg) <= 0) goto err; |
158 | 158 | ||
159 | for (i=0; i<bs->length; i++) | 159 | for (i=0; i<bs->length; i++) |
160 | { | 160 | { |
161 | if (BIO_printf(bp,"%02x%c",bs->data[i], | 161 | if (BIO_printf(bp,"%02x%c",bs->data[i], |
162 | ((i+1 == bs->length)?'\n':':')) <= 0) | 162 | ((i+1 == bs->length)?'\n':':')) <= 0) |
163 | goto err; | 163 | goto err; |
164 | } | ||
165 | } | 164 | } |
166 | |||
167 | } | 165 | } |
168 | 166 | ||
167 | } | ||
168 | |||
169 | if(!(cflag & X509_FLAG_NO_SIGNAME)) | 169 | if(!(cflag & X509_FLAG_NO_SIGNAME)) |
170 | { | 170 | { |
171 | if(X509_signature_print(bp, x->sig_alg, NULL) <= 0) | 171 | if(X509_signature_print(bp, x->sig_alg, NULL) <= 0) |
172 | goto err; | 172 | goto err; |
173 | #if 0 | 173 | #if 0 |
@@ -178,31 +178,31 @@ int X509_print_ex(BIO *bp, X509 *x, unsigned long nmflags, unsigned long cflag) | |||
178 | if (BIO_puts(bp, "\n") <= 0) | 178 | if (BIO_puts(bp, "\n") <= 0) |
179 | goto err; | 179 | goto err; |
180 | #endif | 180 | #endif |
181 | } | 181 | } |
182 | 182 | ||
183 | if(!(cflag & X509_FLAG_NO_ISSUER)) | 183 | if(!(cflag & X509_FLAG_NO_ISSUER)) |
184 | { | 184 | { |
185 | if (BIO_printf(bp," Issuer:%c",mlch) <= 0) goto err; | 185 | if (BIO_printf(bp," Issuer:%c",mlch) <= 0) goto err; |
186 | if (X509_NAME_print_ex(bp,X509_get_issuer_name(x),nmindent, nmflags) < 0) goto err; | 186 | if (X509_NAME_print_ex(bp,X509_get_issuer_name(x),nmindent, nmflags) < 0) goto err; |
187 | if (BIO_write(bp,"\n",1) <= 0) goto err; | 187 | if (BIO_write(bp,"\n",1) <= 0) goto err; |
188 | } | 188 | } |
189 | if(!(cflag & X509_FLAG_NO_VALIDITY)) | 189 | if(!(cflag & X509_FLAG_NO_VALIDITY)) |
190 | { | 190 | { |
191 | if (BIO_write(bp," Validity\n",17) <= 0) goto err; | 191 | if (BIO_write(bp," Validity\n",17) <= 0) goto err; |
192 | if (BIO_write(bp," Not Before: ",24) <= 0) goto err; | 192 | if (BIO_write(bp," Not Before: ",24) <= 0) goto err; |
193 | if (!ASN1_TIME_print(bp,X509_get_notBefore(x))) goto err; | 193 | if (!ASN1_TIME_print(bp,X509_get_notBefore(x))) goto err; |
194 | if (BIO_write(bp,"\n Not After : ",25) <= 0) goto err; | 194 | if (BIO_write(bp,"\n Not After : ",25) <= 0) goto err; |
195 | if (!ASN1_TIME_print(bp,X509_get_notAfter(x))) goto err; | 195 | if (!ASN1_TIME_print(bp,X509_get_notAfter(x))) goto err; |
196 | if (BIO_write(bp,"\n",1) <= 0) goto err; | 196 | if (BIO_write(bp,"\n",1) <= 0) goto err; |
197 | } | 197 | } |
198 | if(!(cflag & X509_FLAG_NO_SUBJECT)) | 198 | if(!(cflag & X509_FLAG_NO_SUBJECT)) |
199 | { | 199 | { |
200 | if (BIO_printf(bp," Subject:%c",mlch) <= 0) goto err; | 200 | if (BIO_printf(bp," Subject:%c",mlch) <= 0) goto err; |
201 | if (X509_NAME_print_ex(bp,X509_get_subject_name(x),nmindent, nmflags) < 0) goto err; | 201 | if (X509_NAME_print_ex(bp,X509_get_subject_name(x),nmindent, nmflags) < 0) goto err; |
202 | if (BIO_write(bp,"\n",1) <= 0) goto err; | 202 | if (BIO_write(bp,"\n",1) <= 0) goto err; |
203 | } | 203 | } |
204 | if(!(cflag & X509_FLAG_NO_PUBKEY)) | 204 | if(!(cflag & X509_FLAG_NO_PUBKEY)) |
205 | { | 205 | { |
206 | if (BIO_write(bp," Subject Public Key Info:\n",33) <= 0) | 206 | if (BIO_write(bp," Subject Public Key Info:\n",33) <= 0) |
207 | goto err; | 207 | goto err; |
208 | if (BIO_printf(bp,"%12sPublic Key Algorithm: ","") <= 0) | 208 | if (BIO_printf(bp,"%12sPublic Key Algorithm: ","") <= 0) |
@@ -214,37 +214,37 @@ int X509_print_ex(BIO *bp, X509 *x, unsigned long nmflags, unsigned long cflag) | |||
214 | 214 | ||
215 | pkey=X509_get_pubkey(x); | 215 | pkey=X509_get_pubkey(x); |
216 | if (pkey == NULL) | 216 | if (pkey == NULL) |
217 | { | 217 | { |
218 | BIO_printf(bp,"%12sUnable to load Public Key\n",""); | 218 | BIO_printf(bp,"%12sUnable to load Public Key\n",""); |
219 | ERR_print_errors(bp); | 219 | ERR_print_errors(bp); |
220 | } | 220 | } |
221 | else | 221 | else |
222 | { | 222 | { |
223 | EVP_PKEY_print_public(bp, pkey, 16, NULL); | 223 | EVP_PKEY_print_public(bp, pkey, 16, NULL); |
224 | EVP_PKEY_free(pkey); | 224 | EVP_PKEY_free(pkey); |
225 | } | ||
226 | } | 225 | } |
226 | } | ||
227 | 227 | ||
228 | if (!(cflag & X509_FLAG_NO_EXTENSIONS)) | 228 | if (!(cflag & X509_FLAG_NO_EXTENSIONS)) |
229 | X509V3_extensions_print(bp, "X509v3 extensions", | 229 | X509V3_extensions_print(bp, "X509v3 extensions", |
230 | ci->extensions, cflag, 8); | 230 | ci->extensions, cflag, 8); |
231 | 231 | ||
232 | if(!(cflag & X509_FLAG_NO_SIGDUMP)) | 232 | if(!(cflag & X509_FLAG_NO_SIGDUMP)) |
233 | { | 233 | { |
234 | if(X509_signature_print(bp, x->sig_alg, x->signature) <= 0) goto err; | 234 | if(X509_signature_print(bp, x->sig_alg, x->signature) <= 0) goto err; |
235 | } | 235 | } |
236 | if(!(cflag & X509_FLAG_NO_AUX)) | 236 | if(!(cflag & X509_FLAG_NO_AUX)) |
237 | { | 237 | { |
238 | if (!X509_CERT_AUX_print(bp, x->aux, 0)) goto err; | 238 | if (!X509_CERT_AUX_print(bp, x->aux, 0)) goto err; |
239 | } | 239 | } |
240 | ret=1; | 240 | ret=1; |
241 | err: | 241 | err: |
242 | if (m != NULL) free(m); | 242 | if (m != NULL) free(m); |
243 | return(ret); | 243 | return(ret); |
244 | } | 244 | } |
245 | 245 | ||
246 | int X509_ocspid_print (BIO *bp, X509 *x) | 246 | int X509_ocspid_print (BIO *bp, X509 *x) |
247 | { | 247 | { |
248 | unsigned char *der=NULL ; | 248 | unsigned char *der=NULL ; |
249 | unsigned char *dertmp; | 249 | unsigned char *dertmp; |
250 | int derlen; | 250 | int derlen; |
@@ -263,9 +263,9 @@ int X509_ocspid_print (BIO *bp, X509 *x) | |||
263 | if (!EVP_Digest(der, derlen, SHA1md, NULL, EVP_sha1(), NULL)) | 263 | if (!EVP_Digest(der, derlen, SHA1md, NULL, EVP_sha1(), NULL)) |
264 | goto err; | 264 | goto err; |
265 | for (i=0; i < SHA_DIGEST_LENGTH; i++) | 265 | for (i=0; i < SHA_DIGEST_LENGTH; i++) |
266 | { | 266 | { |
267 | if (BIO_printf(bp,"%02X",SHA1md[i]) <= 0) goto err; | 267 | if (BIO_printf(bp,"%02X",SHA1md[i]) <= 0) goto err; |
268 | } | 268 | } |
269 | free (der); | 269 | free (der); |
270 | der=NULL; | 270 | der=NULL; |
271 | 271 | ||
@@ -279,17 +279,17 @@ int X509_ocspid_print (BIO *bp, X509 *x) | |||
279 | SHA1md, NULL, EVP_sha1(), NULL)) | 279 | SHA1md, NULL, EVP_sha1(), NULL)) |
280 | goto err; | 280 | goto err; |
281 | for (i=0; i < SHA_DIGEST_LENGTH; i++) | 281 | for (i=0; i < SHA_DIGEST_LENGTH; i++) |
282 | { | 282 | { |
283 | if (BIO_printf(bp,"%02X",SHA1md[i]) <= 0) | 283 | if (BIO_printf(bp,"%02X",SHA1md[i]) <= 0) |
284 | goto err; | 284 | goto err; |
285 | } | 285 | } |
286 | BIO_printf(bp,"\n"); | 286 | BIO_printf(bp,"\n"); |
287 | 287 | ||
288 | return (1); | 288 | return (1); |
289 | err: | 289 | err: |
290 | if (der != NULL) free(der); | 290 | if (der != NULL) free(der); |
291 | return(0); | 291 | return(0); |
292 | } | 292 | } |
293 | 293 | ||
294 | int X509_signature_dump(BIO *bp, const ASN1_STRING *sig, int indent) | 294 | int X509_signature_dump(BIO *bp, const ASN1_STRING *sig, int indent) |
295 | { | 295 | { |
@@ -299,15 +299,15 @@ int X509_signature_dump(BIO *bp, const ASN1_STRING *sig, int indent) | |||
299 | n=sig->length; | 299 | n=sig->length; |
300 | s=sig->data; | 300 | s=sig->data; |
301 | for (i=0; i<n; i++) | 301 | for (i=0; i<n; i++) |
302 | { | 302 | { |
303 | if ((i%18) == 0) | 303 | if ((i%18) == 0) |
304 | { | 304 | { |
305 | if (BIO_write(bp,"\n",1) <= 0) return 0; | 305 | if (BIO_write(bp,"\n",1) <= 0) return 0; |
306 | if (BIO_indent(bp, indent, indent) <= 0) return 0; | 306 | if (BIO_indent(bp, indent, indent) <= 0) return 0; |
307 | } | 307 | } |
308 | if (BIO_printf(bp,"%02x%s",s[i], | 308 | if (BIO_printf(bp,"%02x%s",s[i], |
309 | ((i+1) == n)?"":":") <= 0) return 0; | 309 | ((i+1) == n)?"":":") <= 0) return 0; |
310 | } | 310 | } |
311 | if (BIO_write(bp,"\n",1) != 1) return 0; | 311 | if (BIO_write(bp,"\n",1) != 1) return 0; |
312 | 312 | ||
313 | return 1; | 313 | return 1; |
@@ -321,16 +321,16 @@ int X509_signature_print(BIO *bp, X509_ALGOR *sigalg, ASN1_STRING *sig) | |||
321 | 321 | ||
322 | sig_nid = OBJ_obj2nid(sigalg->algorithm); | 322 | sig_nid = OBJ_obj2nid(sigalg->algorithm); |
323 | if (sig_nid != NID_undef) | 323 | if (sig_nid != NID_undef) |
324 | { | 324 | { |
325 | int pkey_nid, dig_nid; | 325 | int pkey_nid, dig_nid; |
326 | const EVP_PKEY_ASN1_METHOD *ameth; | 326 | const EVP_PKEY_ASN1_METHOD *ameth; |
327 | if (OBJ_find_sigid_algs(sig_nid, &dig_nid, &pkey_nid)) | 327 | if (OBJ_find_sigid_algs(sig_nid, &dig_nid, &pkey_nid)) |
328 | { | 328 | { |
329 | ameth = EVP_PKEY_asn1_find(NULL, pkey_nid); | 329 | ameth = EVP_PKEY_asn1_find(NULL, pkey_nid); |
330 | if (ameth && ameth->sig_print) | 330 | if (ameth && ameth->sig_print) |
331 | return ameth->sig_print(bp, sigalg, sig, 9, 0); | 331 | return ameth->sig_print(bp, sigalg, sig, 9, 0); |
332 | } | ||
333 | } | 332 | } |
333 | } | ||
334 | if (sig) | 334 | if (sig) |
335 | return X509_signature_dump(bp, sig, 9); | 335 | return X509_signature_dump(bp, sig, 9); |
336 | else if (BIO_puts(bp, "\n") <= 0) | 336 | else if (BIO_puts(bp, "\n") <= 0) |
@@ -339,7 +339,7 @@ int X509_signature_print(BIO *bp, X509_ALGOR *sigalg, ASN1_STRING *sig) | |||
339 | } | 339 | } |
340 | 340 | ||
341 | int ASN1_STRING_print(BIO *bp, const ASN1_STRING *v) | 341 | int ASN1_STRING_print(BIO *bp, const ASN1_STRING *v) |
342 | { | 342 | { |
343 | int i,n; | 343 | int i,n; |
344 | char buf[80]; | 344 | char buf[80]; |
345 | const char *p; | 345 | const char *p; |
@@ -348,7 +348,7 @@ int ASN1_STRING_print(BIO *bp, const ASN1_STRING *v) | |||
348 | n=0; | 348 | n=0; |
349 | p=(const char *)v->data; | 349 | p=(const char *)v->data; |
350 | for (i=0; i<v->length; i++) | 350 | for (i=0; i<v->length; i++) |
351 | { | 351 | { |
352 | if ((p[i] > '~') || ((p[i] < ' ') && | 352 | if ((p[i] > '~') || ((p[i] < ' ') && |
353 | (p[i] != '\n') && (p[i] != '\r'))) | 353 | (p[i] != '\n') && (p[i] != '\r'))) |
354 | buf[n]='.'; | 354 | buf[n]='.'; |
@@ -356,17 +356,17 @@ int ASN1_STRING_print(BIO *bp, const ASN1_STRING *v) | |||
356 | buf[n]=p[i]; | 356 | buf[n]=p[i]; |
357 | n++; | 357 | n++; |
358 | if (n >= 80) | 358 | if (n >= 80) |
359 | { | 359 | { |
360 | if (BIO_write(bp,buf,n) <= 0) | 360 | if (BIO_write(bp,buf,n) <= 0) |
361 | return(0); | 361 | return(0); |
362 | n=0; | 362 | n=0; |
363 | } | ||
364 | } | 363 | } |
364 | } | ||
365 | if (n > 0) | 365 | if (n > 0) |
366 | if (BIO_write(bp,buf,n) <= 0) | 366 | if (BIO_write(bp,buf,n) <= 0) |
367 | return(0); | 367 | return(0); |
368 | return(1); | 368 | return(1); |
369 | } | 369 | } |
370 | 370 | ||
371 | int ASN1_TIME_print(BIO *bp, const ASN1_TIME *tm) | 371 | int ASN1_TIME_print(BIO *bp, const ASN1_TIME *tm) |
372 | { | 372 | { |
@@ -384,7 +384,7 @@ static const char *mon[12]= | |||
384 | }; | 384 | }; |
385 | 385 | ||
386 | int ASN1_GENERALIZEDTIME_print(BIO *bp, const ASN1_GENERALIZEDTIME *tm) | 386 | int ASN1_GENERALIZEDTIME_print(BIO *bp, const ASN1_GENERALIZEDTIME *tm) |
387 | { | 387 | { |
388 | char *v; | 388 | char *v; |
389 | int gmt=0; | 389 | int gmt=0; |
390 | int i; | 390 | int i; |
@@ -408,18 +408,18 @@ int ASN1_GENERALIZEDTIME_print(BIO *bp, const ASN1_GENERALIZEDTIME *tm) | |||
408 | if (tm->length >= 14 && | 408 | if (tm->length >= 14 && |
409 | (v[12] >= '0') && (v[12] <= '9') && | 409 | (v[12] >= '0') && (v[12] <= '9') && |
410 | (v[13] >= '0') && (v[13] <= '9')) | 410 | (v[13] >= '0') && (v[13] <= '9')) |
411 | { | 411 | { |
412 | s= (v[12]-'0')*10+(v[13]-'0'); | 412 | s= (v[12]-'0')*10+(v[13]-'0'); |
413 | /* Check for fractions of seconds. */ | 413 | /* Check for fractions of seconds. */ |
414 | if (tm->length >= 15 && v[14] == '.') | 414 | if (tm->length >= 15 && v[14] == '.') |
415 | { | 415 | { |
416 | int l = tm->length; | 416 | int l = tm->length; |
417 | f = &v[14]; /* The decimal point. */ | 417 | f = &v[14]; /* The decimal point. */ |
418 | f_len = 1; | 418 | f_len = 1; |
419 | while (14 + f_len < l && f[f_len] >= '0' && f[f_len] <= '9') | 419 | while (14 + f_len < l && f[f_len] >= '0' && f[f_len] <= '9') |
420 | ++f_len; | 420 | ++f_len; |
421 | } | ||
422 | } | 421 | } |
422 | } | ||
423 | 423 | ||
424 | if (BIO_printf(bp,"%s %2d %02d:%02d:%02d%.*s %d%s", | 424 | if (BIO_printf(bp,"%s %2d %02d:%02d:%02d%.*s %d%s", |
425 | mon[M-1],d,h,m,s,f_len,f,y,(gmt)?" GMT":"") <= 0) | 425 | mon[M-1],d,h,m,s,f_len,f,y,(gmt)?" GMT":"") <= 0) |
@@ -429,10 +429,10 @@ int ASN1_GENERALIZEDTIME_print(BIO *bp, const ASN1_GENERALIZEDTIME *tm) | |||
429 | err: | 429 | err: |
430 | BIO_write(bp,"Bad time value",14); | 430 | BIO_write(bp,"Bad time value",14); |
431 | return(0); | 431 | return(0); |
432 | } | 432 | } |
433 | 433 | ||
434 | int ASN1_UTCTIME_print(BIO *bp, const ASN1_UTCTIME *tm) | 434 | int ASN1_UTCTIME_print(BIO *bp, const ASN1_UTCTIME *tm) |
435 | { | 435 | { |
436 | const char *v; | 436 | const char *v; |
437 | int gmt=0; | 437 | int gmt=0; |
438 | int i; | 438 | int i; |
@@ -465,10 +465,10 @@ int ASN1_UTCTIME_print(BIO *bp, const ASN1_UTCTIME *tm) | |||
465 | err: | 465 | err: |
466 | BIO_write(bp,"Bad time value",14); | 466 | BIO_write(bp,"Bad time value",14); |
467 | return(0); | 467 | return(0); |
468 | } | 468 | } |
469 | 469 | ||
470 | int X509_NAME_print(BIO *bp, X509_NAME *name, int obase) | 470 | int X509_NAME_print(BIO *bp, X509_NAME *name, int obase) |
471 | { | 471 | { |
472 | char *s,*c,*b; | 472 | char *s,*c,*b; |
473 | int ret=0,l,i; | 473 | int ret=0,l,i; |
474 | 474 | ||
@@ -476,15 +476,15 @@ int X509_NAME_print(BIO *bp, X509_NAME *name, int obase) | |||
476 | 476 | ||
477 | b=X509_NAME_oneline(name,NULL,0); | 477 | b=X509_NAME_oneline(name,NULL,0); |
478 | if (!*b) | 478 | if (!*b) |
479 | { | 479 | { |
480 | free(b); | 480 | free(b); |
481 | return 1; | 481 | return 1; |
482 | } | 482 | } |
483 | s=b+1; /* skip the first slash */ | 483 | s=b+1; /* skip the first slash */ |
484 | 484 | ||
485 | c=s; | 485 | c=s; |
486 | for (;;) | 486 | for (;;) |
487 | { | 487 | { |
488 | if ( ((*s == '/') && | 488 | if ( ((*s == '/') && |
489 | ((s[1] >= 'A') && (s[1] <= 'Z') && ( | 489 | ((s[1] >= 'A') && (s[1] <= 'Z') && ( |
490 | (s[2] == '=') || | 490 | (s[2] == '=') || |
@@ -492,27 +492,27 @@ int X509_NAME_print(BIO *bp, X509_NAME *name, int obase) | |||
492 | (s[3] == '=')) | 492 | (s[3] == '=')) |
493 | ))) || | 493 | ))) || |
494 | (*s == '\0')) | 494 | (*s == '\0')) |
495 | { | 495 | { |
496 | i=s-c; | 496 | i=s-c; |
497 | if (BIO_write(bp,c,i) != i) goto err; | 497 | if (BIO_write(bp,c,i) != i) goto err; |
498 | c=s+1; /* skip following slash */ | 498 | c=s+1; /* skip following slash */ |
499 | if (*s != '\0') | 499 | if (*s != '\0') |
500 | { | 500 | { |
501 | if (BIO_write(bp,", ",2) != 2) goto err; | 501 | if (BIO_write(bp,", ",2) != 2) goto err; |
502 | } | ||
503 | l--; | ||
504 | } | 502 | } |
503 | l--; | ||
504 | } | ||
505 | if (*s == '\0') break; | 505 | if (*s == '\0') break; |
506 | s++; | 506 | s++; |
507 | l--; | 507 | l--; |
508 | } | 508 | } |
509 | 509 | ||
510 | ret=1; | 510 | ret=1; |
511 | if (0) | 511 | if (0) |
512 | { | 512 | { |
513 | err: | 513 | err: |
514 | X509err(X509_F_X509_NAME_PRINT,ERR_R_BUF_LIB); | 514 | X509err(X509_F_X509_NAME_PRINT,ERR_R_BUF_LIB); |
515 | } | 515 | } |
516 | free(b); | 516 | free(b); |
517 | return(ret); | 517 | return(ret); |
518 | } | 518 | } |
diff --git a/src/lib/libcrypto/asn1/tasn_dec.c b/src/lib/libcrypto/asn1/tasn_dec.c index c594db9140..0df42a4a93 100644 --- a/src/lib/libcrypto/asn1/tasn_dec.c +++ b/src/lib/libcrypto/asn1/tasn_dec.c | |||
@@ -103,13 +103,13 @@ B_ASN1_T61STRING,B_ASN1_VIDEOTEXSTRING,B_ASN1_IA5STRING, /* tags 20-22 */ | |||
103 | B_ASN1_UTCTIME, B_ASN1_GENERALIZEDTIME, /* tags 23-24 */ | 103 | B_ASN1_UTCTIME, B_ASN1_GENERALIZEDTIME, /* tags 23-24 */ |
104 | B_ASN1_GRAPHICSTRING,B_ASN1_ISO64STRING,B_ASN1_GENERALSTRING, /* tags 25-27 */ | 104 | B_ASN1_GRAPHICSTRING,B_ASN1_ISO64STRING,B_ASN1_GENERALSTRING, /* tags 25-27 */ |
105 | B_ASN1_UNIVERSALSTRING,B_ASN1_UNKNOWN,B_ASN1_BMPSTRING,B_ASN1_UNKNOWN, /* tags 28-31 */ | 105 | B_ASN1_UNIVERSALSTRING,B_ASN1_UNKNOWN,B_ASN1_BMPSTRING,B_ASN1_UNKNOWN, /* tags 28-31 */ |
106 | }; | 106 | }; |
107 | 107 | ||
108 | unsigned long ASN1_tag2bit(int tag) | 108 | unsigned long ASN1_tag2bit(int tag) |
109 | { | 109 | { |
110 | if ((tag < 0) || (tag > 30)) return 0; | 110 | if ((tag < 0) || (tag > 30)) return 0; |
111 | return tag2bit[tag]; | 111 | return tag2bit[tag]; |
112 | } | 112 | } |
113 | 113 | ||
114 | /* Macro to initialize and invalidate the cache */ | 114 | /* Macro to initialize and invalidate the cache */ |
115 | 115 | ||
@@ -127,7 +127,7 @@ unsigned long ASN1_tag2bit(int tag) | |||
127 | 127 | ||
128 | ASN1_VALUE *ASN1_item_d2i(ASN1_VALUE **pval, | 128 | ASN1_VALUE *ASN1_item_d2i(ASN1_VALUE **pval, |
129 | const unsigned char **in, long len, const ASN1_ITEM *it) | 129 | const unsigned char **in, long len, const ASN1_ITEM *it) |
130 | { | 130 | { |
131 | ASN1_TLC c; | 131 | ASN1_TLC c; |
132 | ASN1_VALUE *ptmpval = NULL; | 132 | ASN1_VALUE *ptmpval = NULL; |
133 | if (!pval) | 133 | if (!pval) |
@@ -136,15 +136,15 @@ ASN1_VALUE *ASN1_item_d2i(ASN1_VALUE **pval, | |||
136 | if (ASN1_item_ex_d2i(pval, in, len, it, -1, 0, 0, &c) > 0) | 136 | if (ASN1_item_ex_d2i(pval, in, len, it, -1, 0, 0, &c) > 0) |
137 | return *pval; | 137 | return *pval; |
138 | return NULL; | 138 | return NULL; |
139 | } | 139 | } |
140 | 140 | ||
141 | int ASN1_template_d2i(ASN1_VALUE **pval, | 141 | int ASN1_template_d2i(ASN1_VALUE **pval, |
142 | const unsigned char **in, long len, const ASN1_TEMPLATE *tt) | 142 | const unsigned char **in, long len, const ASN1_TEMPLATE *tt) |
143 | { | 143 | { |
144 | ASN1_TLC c; | 144 | ASN1_TLC c; |
145 | asn1_tlc_clear_nc(&c); | 145 | asn1_tlc_clear_nc(&c); |
146 | return asn1_template_ex_d2i(pval, in, len, tt, 0, &c); | 146 | return asn1_template_ex_d2i(pval, in, len, tt, 0, &c); |
147 | } | 147 | } |
148 | 148 | ||
149 | 149 | ||
150 | /* Decode an item, taking care of IMPLICIT tagging, if any. | 150 | /* Decode an item, taking care of IMPLICIT tagging, if any. |
@@ -154,7 +154,7 @@ int ASN1_template_d2i(ASN1_VALUE **pval, | |||
154 | int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, | 154 | int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, |
155 | const ASN1_ITEM *it, | 155 | const ASN1_ITEM *it, |
156 | int tag, int aclass, char opt, ASN1_TLC *ctx) | 156 | int tag, int aclass, char opt, ASN1_TLC *ctx) |
157 | { | 157 | { |
158 | const ASN1_TEMPLATE *tt, *errtt = NULL; | 158 | const ASN1_TEMPLATE *tt, *errtt = NULL; |
159 | const ASN1_COMPAT_FUNCS *cf; | 159 | const ASN1_COMPAT_FUNCS *cf; |
160 | const ASN1_EXTERN_FUNCS *ef; | 160 | const ASN1_EXTERN_FUNCS *ef; |
@@ -176,10 +176,10 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, | |||
176 | else asn1_cb = 0; | 176 | else asn1_cb = 0; |
177 | 177 | ||
178 | switch(it->itype) | 178 | switch(it->itype) |
179 | { | 179 | { |
180 | case ASN1_ITYPE_PRIMITIVE: | 180 | case ASN1_ITYPE_PRIMITIVE: |
181 | if (it->templates) | 181 | if (it->templates) |
182 | { | 182 | { |
183 | /* tagging or OPTIONAL is currently illegal on an item | 183 | /* tagging or OPTIONAL is currently illegal on an item |
184 | * template because the flags can't get passed down. | 184 | * template because the flags can't get passed down. |
185 | * In practice this isn't a problem: we include the | 185 | * In practice this isn't a problem: we include the |
@@ -187,14 +187,14 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, | |||
187 | * template itself. | 187 | * template itself. |
188 | */ | 188 | */ |
189 | if ((tag != -1) || opt) | 189 | if ((tag != -1) || opt) |
190 | { | 190 | { |
191 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, | 191 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, |
192 | ASN1_R_ILLEGAL_OPTIONS_ON_ITEM_TEMPLATE); | 192 | ASN1_R_ILLEGAL_OPTIONS_ON_ITEM_TEMPLATE); |
193 | goto err; | 193 | goto err; |
194 | } | 194 | } |
195 | return asn1_template_ex_d2i(pval, in, len, | 195 | return asn1_template_ex_d2i(pval, in, len, |
196 | it->templates, opt, ctx); | 196 | it->templates, opt, ctx); |
197 | } | 197 | } |
198 | return asn1_d2i_ex_primitive(pval, in, len, it, | 198 | return asn1_d2i_ex_primitive(pval, in, len, it, |
199 | tag, aclass, opt, ctx); | 199 | tag, aclass, opt, ctx); |
200 | break; | 200 | break; |
@@ -205,31 +205,31 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, | |||
205 | ret = asn1_check_tlen(NULL, &otag, &oclass, NULL, NULL, | 205 | ret = asn1_check_tlen(NULL, &otag, &oclass, NULL, NULL, |
206 | &p, len, -1, 0, 1, ctx); | 206 | &p, len, -1, 0, 1, ctx); |
207 | if (!ret) | 207 | if (!ret) |
208 | { | 208 | { |
209 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, | 209 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, |
210 | ERR_R_NESTED_ASN1_ERROR); | 210 | ERR_R_NESTED_ASN1_ERROR); |
211 | goto err; | 211 | goto err; |
212 | } | 212 | } |
213 | 213 | ||
214 | /* Must be UNIVERSAL class */ | 214 | /* Must be UNIVERSAL class */ |
215 | if (oclass != V_ASN1_UNIVERSAL) | 215 | if (oclass != V_ASN1_UNIVERSAL) |
216 | { | 216 | { |
217 | /* If OPTIONAL, assume this is OK */ | 217 | /* If OPTIONAL, assume this is OK */ |
218 | if (opt) return -1; | 218 | if (opt) return -1; |
219 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, | 219 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, |
220 | ASN1_R_MSTRING_NOT_UNIVERSAL); | 220 | ASN1_R_MSTRING_NOT_UNIVERSAL); |
221 | goto err; | 221 | goto err; |
222 | } | 222 | } |
223 | /* Check tag matches bit map */ | 223 | /* Check tag matches bit map */ |
224 | if (!(ASN1_tag2bit(otag) & it->utype)) | 224 | if (!(ASN1_tag2bit(otag) & it->utype)) |
225 | { | 225 | { |
226 | /* If OPTIONAL, assume this is OK */ | 226 | /* If OPTIONAL, assume this is OK */ |
227 | if (opt) | 227 | if (opt) |
228 | return -1; | 228 | return -1; |
229 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, | 229 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, |
230 | ASN1_R_MSTRING_WRONG_TAG); | 230 | ASN1_R_MSTRING_WRONG_TAG); |
231 | goto err; | 231 | goto err; |
232 | } | 232 | } |
233 | return asn1_d2i_ex_primitive(pval, in, len, | 233 | return asn1_d2i_ex_primitive(pval, in, len, |
234 | it, otag, 0, 0, ctx); | 234 | it, otag, 0, 0, ctx); |
235 | 235 | ||
@@ -245,7 +245,7 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, | |||
245 | 245 | ||
246 | /* If OPTIONAL see if it is there */ | 246 | /* If OPTIONAL see if it is there */ |
247 | if (opt) | 247 | if (opt) |
248 | { | 248 | { |
249 | int exptag; | 249 | int exptag; |
250 | p = *in; | 250 | p = *in; |
251 | if (tag == -1) | 251 | if (tag == -1) |
@@ -257,14 +257,14 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, | |||
257 | ret = asn1_check_tlen(NULL, NULL, NULL, NULL, NULL, | 257 | ret = asn1_check_tlen(NULL, NULL, NULL, NULL, NULL, |
258 | &p, len, exptag, aclass, 1, ctx); | 258 | &p, len, exptag, aclass, 1, ctx); |
259 | if (!ret) | 259 | if (!ret) |
260 | { | 260 | { |
261 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, | 261 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, |
262 | ERR_R_NESTED_ASN1_ERROR); | 262 | ERR_R_NESTED_ASN1_ERROR); |
263 | goto err; | 263 | goto err; |
264 | } | 264 | } |
265 | if (ret == -1) | 265 | if (ret == -1) |
266 | return -1; | 266 | return -1; |
267 | } | 267 | } |
268 | 268 | ||
269 | /* This is the old style evil hack IMPLICIT handling: | 269 | /* This is the old style evil hack IMPLICIT handling: |
270 | * since the underlying code is expecting a tag and | 270 | * since the underlying code is expecting a tag and |
@@ -282,18 +282,18 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, | |||
282 | */ | 282 | */ |
283 | 283 | ||
284 | if (tag != -1) | 284 | if (tag != -1) |
285 | { | 285 | { |
286 | wp = *(unsigned char **)in; | 286 | wp = *(unsigned char **)in; |
287 | imphack = *wp; | 287 | imphack = *wp; |
288 | if (p == NULL) | 288 | if (p == NULL) |
289 | { | 289 | { |
290 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, | 290 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, |
291 | ERR_R_NESTED_ASN1_ERROR); | 291 | ERR_R_NESTED_ASN1_ERROR); |
292 | goto err; | 292 | goto err; |
293 | } | 293 | } |
294 | *wp = (unsigned char)((*p & V_ASN1_CONSTRUCTED) | 294 | *wp = (unsigned char)((*p & V_ASN1_CONSTRUCTED) |
295 | | it->utype); | 295 | | it->utype); |
296 | } | 296 | } |
297 | 297 | ||
298 | ptmpval = cf->asn1_d2i(pval, in, len); | 298 | ptmpval = cf->asn1_d2i(pval, in, len); |
299 | 299 | ||
@@ -313,15 +313,15 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, | |||
313 | 313 | ||
314 | /* Allocate structure */ | 314 | /* Allocate structure */ |
315 | if (!*pval && !ASN1_item_ex_new(pval, it)) | 315 | if (!*pval && !ASN1_item_ex_new(pval, it)) |
316 | { | 316 | { |
317 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, | 317 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, |
318 | ERR_R_NESTED_ASN1_ERROR); | 318 | ERR_R_NESTED_ASN1_ERROR); |
319 | goto err; | 319 | goto err; |
320 | } | 320 | } |
321 | /* CHOICE type, try each possibility in turn */ | 321 | /* CHOICE type, try each possibility in turn */ |
322 | p = *in; | 322 | p = *in; |
323 | for (i = 0, tt=it->templates; i < it->tcount; i++, tt++) | 323 | for (i = 0, tt=it->templates; i < it->tcount; i++, tt++) |
324 | { | 324 | { |
325 | pchptr = asn1_get_field_ptr(pval, tt); | 325 | pchptr = asn1_get_field_ptr(pval, tt); |
326 | /* We mark field as OPTIONAL so its absence | 326 | /* We mark field as OPTIONAL so its absence |
327 | * can be recognised. | 327 | * can be recognised. |
@@ -338,22 +338,22 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, | |||
338 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, | 338 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, |
339 | ERR_R_NESTED_ASN1_ERROR); | 339 | ERR_R_NESTED_ASN1_ERROR); |
340 | goto err; | 340 | goto err; |
341 | } | 341 | } |
342 | 342 | ||
343 | /* Did we fall off the end without reading anything? */ | 343 | /* Did we fall off the end without reading anything? */ |
344 | if (i == it->tcount) | 344 | if (i == it->tcount) |
345 | { | 345 | { |
346 | /* If OPTIONAL, this is OK */ | 346 | /* If OPTIONAL, this is OK */ |
347 | if (opt) | 347 | if (opt) |
348 | { | 348 | { |
349 | /* Free and zero it */ | 349 | /* Free and zero it */ |
350 | ASN1_item_ex_free(pval, it); | 350 | ASN1_item_ex_free(pval, it); |
351 | return -1; | 351 | return -1; |
352 | } | 352 | } |
353 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, | 353 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, |
354 | ASN1_R_NO_MATCHING_CHOICE_TYPE); | 354 | ASN1_R_NO_MATCHING_CHOICE_TYPE); |
355 | goto err; | 355 | goto err; |
356 | } | 356 | } |
357 | 357 | ||
358 | asn1_set_choice_selector(pval, i, it); | 358 | asn1_set_choice_selector(pval, i, it); |
359 | *in = p; | 359 | *in = p; |
@@ -368,48 +368,48 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, | |||
368 | 368 | ||
369 | /* If no IMPLICIT tagging set to SEQUENCE, UNIVERSAL */ | 369 | /* If no IMPLICIT tagging set to SEQUENCE, UNIVERSAL */ |
370 | if (tag == -1) | 370 | if (tag == -1) |
371 | { | 371 | { |
372 | tag = V_ASN1_SEQUENCE; | 372 | tag = V_ASN1_SEQUENCE; |
373 | aclass = V_ASN1_UNIVERSAL; | 373 | aclass = V_ASN1_UNIVERSAL; |
374 | } | 374 | } |
375 | /* Get SEQUENCE length and update len, p */ | 375 | /* Get SEQUENCE length and update len, p */ |
376 | ret = asn1_check_tlen(&len, NULL, NULL, &seq_eoc, &cst, | 376 | ret = asn1_check_tlen(&len, NULL, NULL, &seq_eoc, &cst, |
377 | &p, len, tag, aclass, opt, ctx); | 377 | &p, len, tag, aclass, opt, ctx); |
378 | if (!ret) | 378 | if (!ret) |
379 | { | 379 | { |
380 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, | 380 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, |
381 | ERR_R_NESTED_ASN1_ERROR); | 381 | ERR_R_NESTED_ASN1_ERROR); |
382 | goto err; | 382 | goto err; |
383 | } | 383 | } |
384 | else if (ret == -1) | 384 | else if (ret == -1) |
385 | return -1; | 385 | return -1; |
386 | if (aux && (aux->flags & ASN1_AFLG_BROKEN)) | 386 | if (aux && (aux->flags & ASN1_AFLG_BROKEN)) |
387 | { | 387 | { |
388 | len = tmplen - (p - *in); | 388 | len = tmplen - (p - *in); |
389 | seq_nolen = 1; | 389 | seq_nolen = 1; |
390 | } | 390 | } |
391 | /* If indefinite we don't do a length check */ | 391 | /* If indefinite we don't do a length check */ |
392 | else seq_nolen = seq_eoc; | 392 | else seq_nolen = seq_eoc; |
393 | if (!cst) | 393 | if (!cst) |
394 | { | 394 | { |
395 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, | 395 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, |
396 | ASN1_R_SEQUENCE_NOT_CONSTRUCTED); | 396 | ASN1_R_SEQUENCE_NOT_CONSTRUCTED); |
397 | goto err; | 397 | goto err; |
398 | } | 398 | } |
399 | 399 | ||
400 | if (!*pval && !ASN1_item_ex_new(pval, it)) | 400 | if (!*pval && !ASN1_item_ex_new(pval, it)) |
401 | { | 401 | { |
402 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, | 402 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, |
403 | ERR_R_NESTED_ASN1_ERROR); | 403 | ERR_R_NESTED_ASN1_ERROR); |
404 | goto err; | 404 | goto err; |
405 | } | 405 | } |
406 | 406 | ||
407 | if (asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it, NULL)) | 407 | if (asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it, NULL)) |
408 | goto auxerr; | 408 | goto auxerr; |
409 | 409 | ||
410 | /* Get each field entry */ | 410 | /* Get each field entry */ |
411 | for (i = 0, tt = it->templates; i < it->tcount; i++, tt++) | 411 | for (i = 0, tt = it->templates; i < it->tcount; i++, tt++) |
412 | { | 412 | { |
413 | const ASN1_TEMPLATE *seqtt; | 413 | const ASN1_TEMPLATE *seqtt; |
414 | ASN1_VALUE **pseqval; | 414 | ASN1_VALUE **pseqval; |
415 | seqtt = asn1_do_adb(pval, tt, 1); | 415 | seqtt = asn1_do_adb(pval, tt, 1); |
@@ -421,18 +421,18 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, | |||
421 | break; | 421 | break; |
422 | q = p; | 422 | q = p; |
423 | if (asn1_check_eoc(&p, len)) | 423 | if (asn1_check_eoc(&p, len)) |
424 | { | 424 | { |
425 | if (!seq_eoc) | 425 | if (!seq_eoc) |
426 | { | 426 | { |
427 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, | 427 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, |
428 | ASN1_R_UNEXPECTED_EOC); | 428 | ASN1_R_UNEXPECTED_EOC); |
429 | goto err; | 429 | goto err; |
430 | } | 430 | } |
431 | len -= p - q; | 431 | len -= p - q; |
432 | seq_eoc = 0; | 432 | seq_eoc = 0; |
433 | q = p; | 433 | q = p; |
434 | break; | 434 | break; |
435 | } | 435 | } |
436 | /* This determines the OPTIONAL flag value. The field | 436 | /* This determines the OPTIONAL flag value. The field |
437 | * cannot be omitted if it is the last of a SEQUENCE | 437 | * cannot be omitted if it is the last of a SEQUENCE |
438 | * and there is still data to be read. This isn't | 438 | * and there is still data to be read. This isn't |
@@ -448,60 +448,60 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, | |||
448 | ret = asn1_template_ex_d2i(pseqval, &p, len, | 448 | ret = asn1_template_ex_d2i(pseqval, &p, len, |
449 | seqtt, isopt, ctx); | 449 | seqtt, isopt, ctx); |
450 | if (!ret) | 450 | if (!ret) |
451 | { | 451 | { |
452 | errtt = seqtt; | 452 | errtt = seqtt; |
453 | goto err; | 453 | goto err; |
454 | } | 454 | } |
455 | else if (ret == -1) | 455 | else if (ret == -1) |
456 | { | 456 | { |
457 | /* OPTIONAL component absent. | 457 | /* OPTIONAL component absent. |
458 | * Free and zero the field. | 458 | * Free and zero the field. |
459 | */ | 459 | */ |
460 | ASN1_template_free(pseqval, seqtt); | 460 | ASN1_template_free(pseqval, seqtt); |
461 | continue; | 461 | continue; |
462 | } | 462 | } |
463 | /* Update length */ | 463 | /* Update length */ |
464 | len -= p - q; | 464 | len -= p - q; |
465 | } | 465 | } |
466 | 466 | ||
467 | /* Check for EOC if expecting one */ | 467 | /* Check for EOC if expecting one */ |
468 | if (seq_eoc && !asn1_check_eoc(&p, len)) | 468 | if (seq_eoc && !asn1_check_eoc(&p, len)) |
469 | { | 469 | { |
470 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_MISSING_EOC); | 470 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_MISSING_EOC); |
471 | goto err; | 471 | goto err; |
472 | } | 472 | } |
473 | /* Check all data read */ | 473 | /* Check all data read */ |
474 | if (!seq_nolen && len) | 474 | if (!seq_nolen && len) |
475 | { | 475 | { |
476 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, | 476 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, |
477 | ASN1_R_SEQUENCE_LENGTH_MISMATCH); | 477 | ASN1_R_SEQUENCE_LENGTH_MISMATCH); |
478 | goto err; | 478 | goto err; |
479 | } | 479 | } |
480 | 480 | ||
481 | /* If we get here we've got no more data in the SEQUENCE, | 481 | /* If we get here we've got no more data in the SEQUENCE, |
482 | * however we may not have read all fields so check all | 482 | * however we may not have read all fields so check all |
483 | * remaining are OPTIONAL and clear any that are. | 483 | * remaining are OPTIONAL and clear any that are. |
484 | */ | 484 | */ |
485 | for (; i < it->tcount; tt++, i++) | 485 | for (; i < it->tcount; tt++, i++) |
486 | { | 486 | { |
487 | const ASN1_TEMPLATE *seqtt; | 487 | const ASN1_TEMPLATE *seqtt; |
488 | seqtt = asn1_do_adb(pval, tt, 1); | 488 | seqtt = asn1_do_adb(pval, tt, 1); |
489 | if (!seqtt) | 489 | if (!seqtt) |
490 | goto err; | 490 | goto err; |
491 | if (seqtt->flags & ASN1_TFLG_OPTIONAL) | 491 | if (seqtt->flags & ASN1_TFLG_OPTIONAL) |
492 | { | 492 | { |
493 | ASN1_VALUE **pseqval; | 493 | ASN1_VALUE **pseqval; |
494 | pseqval = asn1_get_field_ptr(pval, seqtt); | 494 | pseqval = asn1_get_field_ptr(pval, seqtt); |
495 | ASN1_template_free(pseqval, seqtt); | 495 | ASN1_template_free(pseqval, seqtt); |
496 | } | 496 | } |
497 | else | 497 | else |
498 | { | 498 | { |
499 | errtt = seqtt; | 499 | errtt = seqtt; |
500 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, | 500 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, |
501 | ASN1_R_FIELD_MISSING); | 501 | ASN1_R_FIELD_MISSING); |
502 | goto err; | 502 | goto err; |
503 | } | ||
504 | } | 503 | } |
504 | } | ||
505 | /* Save encoding */ | 505 | /* Save encoding */ |
506 | if (!asn1_enc_save(pval, *in, p - *in, it)) | 506 | if (!asn1_enc_save(pval, *in, p - *in, it)) |
507 | goto auxerr; | 507 | goto auxerr; |
@@ -512,7 +512,7 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, | |||
512 | 512 | ||
513 | default: | 513 | default: |
514 | return 0; | 514 | return 0; |
515 | } | 515 | } |
516 | auxerr: | 516 | auxerr: |
517 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_AUX_ERROR); | 517 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_AUX_ERROR); |
518 | err: | 518 | err: |
@@ -523,7 +523,7 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, | |||
523 | else | 523 | else |
524 | ERR_add_error_data(2, "Type=", it->sname); | 524 | ERR_add_error_data(2, "Type=", it->sname); |
525 | return 0; | 525 | return 0; |
526 | } | 526 | } |
527 | 527 | ||
528 | /* Templates are handled with two separate functions. | 528 | /* Templates are handled with two separate functions. |
529 | * One handles any EXPLICIT tag and the other handles the rest. | 529 | * One handles any EXPLICIT tag and the other handles the rest. |
@@ -533,7 +533,7 @@ static int asn1_template_ex_d2i(ASN1_VALUE **val, | |||
533 | const unsigned char **in, long inlen, | 533 | const unsigned char **in, long inlen, |
534 | const ASN1_TEMPLATE *tt, char opt, | 534 | const ASN1_TEMPLATE *tt, char opt, |
535 | ASN1_TLC *ctx) | 535 | ASN1_TLC *ctx) |
536 | { | 536 | { |
537 | int flags, aclass; | 537 | int flags, aclass; |
538 | int ret; | 538 | int ret; |
539 | long len; | 539 | long len; |
@@ -548,7 +548,7 @@ static int asn1_template_ex_d2i(ASN1_VALUE **val, | |||
548 | 548 | ||
549 | /* Check if EXPLICIT tag expected */ | 549 | /* Check if EXPLICIT tag expected */ |
550 | if (flags & ASN1_TFLG_EXPTAG) | 550 | if (flags & ASN1_TFLG_EXPTAG) |
551 | { | 551 | { |
552 | char cst; | 552 | char cst; |
553 | /* Need to work out amount of data available to the inner | 553 | /* Need to work out amount of data available to the inner |
554 | * content and where it starts: so read in EXPLICIT header to | 554 | * content and where it starts: so read in EXPLICIT header to |
@@ -558,51 +558,51 @@ static int asn1_template_ex_d2i(ASN1_VALUE **val, | |||
558 | &p, inlen, tt->tag, aclass, opt, ctx); | 558 | &p, inlen, tt->tag, aclass, opt, ctx); |
559 | q = p; | 559 | q = p; |
560 | if (!ret) | 560 | if (!ret) |
561 | { | 561 | { |
562 | ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, | 562 | ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, |
563 | ERR_R_NESTED_ASN1_ERROR); | 563 | ERR_R_NESTED_ASN1_ERROR); |
564 | return 0; | 564 | return 0; |
565 | } | 565 | } |
566 | else if (ret == -1) | 566 | else if (ret == -1) |
567 | return -1; | 567 | return -1; |
568 | if (!cst) | 568 | if (!cst) |
569 | { | 569 | { |
570 | ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, | 570 | ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, |
571 | ASN1_R_EXPLICIT_TAG_NOT_CONSTRUCTED); | 571 | ASN1_R_EXPLICIT_TAG_NOT_CONSTRUCTED); |
572 | return 0; | 572 | return 0; |
573 | } | 573 | } |
574 | /* We've found the field so it can't be OPTIONAL now */ | 574 | /* We've found the field so it can't be OPTIONAL now */ |
575 | ret = asn1_template_noexp_d2i(val, &p, len, tt, 0, ctx); | 575 | ret = asn1_template_noexp_d2i(val, &p, len, tt, 0, ctx); |
576 | if (!ret) | 576 | if (!ret) |
577 | { | 577 | { |
578 | ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, | 578 | ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, |
579 | ERR_R_NESTED_ASN1_ERROR); | 579 | ERR_R_NESTED_ASN1_ERROR); |
580 | return 0; | 580 | return 0; |
581 | } | 581 | } |
582 | /* We read the field in OK so update length */ | 582 | /* We read the field in OK so update length */ |
583 | len -= p - q; | 583 | len -= p - q; |
584 | if (exp_eoc) | 584 | if (exp_eoc) |
585 | { | 585 | { |
586 | /* If NDEF we must have an EOC here */ | 586 | /* If NDEF we must have an EOC here */ |
587 | if (!asn1_check_eoc(&p, len)) | 587 | if (!asn1_check_eoc(&p, len)) |
588 | { | 588 | { |
589 | ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, | 589 | ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, |
590 | ASN1_R_MISSING_EOC); | 590 | ASN1_R_MISSING_EOC); |
591 | goto err; | 591 | goto err; |
592 | } | ||
593 | } | 592 | } |
593 | } | ||
594 | else | 594 | else |
595 | { | 595 | { |
596 | /* Otherwise we must hit the EXPLICIT tag end or its | 596 | /* Otherwise we must hit the EXPLICIT tag end or its |
597 | * an error */ | 597 | * an error */ |
598 | if (len) | 598 | if (len) |
599 | { | 599 | { |
600 | ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, | 600 | ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, |
601 | ASN1_R_EXPLICIT_LENGTH_MISMATCH); | 601 | ASN1_R_EXPLICIT_LENGTH_MISMATCH); |
602 | goto err; | 602 | goto err; |
603 | } | ||
604 | } | 603 | } |
605 | } | 604 | } |
605 | } | ||
606 | else | 606 | else |
607 | return asn1_template_noexp_d2i(val, in, inlen, | 607 | return asn1_template_noexp_d2i(val, in, inlen, |
608 | tt, opt, ctx); | 608 | tt, opt, ctx); |
@@ -613,13 +613,13 @@ static int asn1_template_ex_d2i(ASN1_VALUE **val, | |||
613 | err: | 613 | err: |
614 | ASN1_template_free(val, tt); | 614 | ASN1_template_free(val, tt); |
615 | return 0; | 615 | return 0; |
616 | } | 616 | } |
617 | 617 | ||
618 | static int asn1_template_noexp_d2i(ASN1_VALUE **val, | 618 | static int asn1_template_noexp_d2i(ASN1_VALUE **val, |
619 | const unsigned char **in, long len, | 619 | const unsigned char **in, long len, |
620 | const ASN1_TEMPLATE *tt, char opt, | 620 | const ASN1_TEMPLATE *tt, char opt, |
621 | ASN1_TLC *ctx) | 621 | ASN1_TLC *ctx) |
622 | { | 622 | { |
623 | int flags, aclass; | 623 | int flags, aclass; |
624 | int ret; | 624 | int ret; |
625 | const unsigned char *p, *q; | 625 | const unsigned char *p, *q; |
@@ -632,128 +632,128 @@ static int asn1_template_noexp_d2i(ASN1_VALUE **val, | |||
632 | q = p; | 632 | q = p; |
633 | 633 | ||
634 | if (flags & ASN1_TFLG_SK_MASK) | 634 | if (flags & ASN1_TFLG_SK_MASK) |
635 | { | 635 | { |
636 | /* SET OF, SEQUENCE OF */ | 636 | /* SET OF, SEQUENCE OF */ |
637 | int sktag, skaclass; | 637 | int sktag, skaclass; |
638 | char sk_eoc; | 638 | char sk_eoc; |
639 | /* First work out expected inner tag value */ | 639 | /* First work out expected inner tag value */ |
640 | if (flags & ASN1_TFLG_IMPTAG) | 640 | if (flags & ASN1_TFLG_IMPTAG) |
641 | { | 641 | { |
642 | sktag = tt->tag; | 642 | sktag = tt->tag; |
643 | skaclass = aclass; | 643 | skaclass = aclass; |
644 | } | 644 | } |
645 | else | 645 | else |
646 | { | 646 | { |
647 | skaclass = V_ASN1_UNIVERSAL; | 647 | skaclass = V_ASN1_UNIVERSAL; |
648 | if (flags & ASN1_TFLG_SET_OF) | 648 | if (flags & ASN1_TFLG_SET_OF) |
649 | sktag = V_ASN1_SET; | 649 | sktag = V_ASN1_SET; |
650 | else | 650 | else |
651 | sktag = V_ASN1_SEQUENCE; | 651 | sktag = V_ASN1_SEQUENCE; |
652 | } | 652 | } |
653 | /* Get the tag */ | 653 | /* Get the tag */ |
654 | ret = asn1_check_tlen(&len, NULL, NULL, &sk_eoc, NULL, | 654 | ret = asn1_check_tlen(&len, NULL, NULL, &sk_eoc, NULL, |
655 | &p, len, sktag, skaclass, opt, ctx); | 655 | &p, len, sktag, skaclass, opt, ctx); |
656 | if (!ret) | 656 | if (!ret) |
657 | { | 657 | { |
658 | ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, | 658 | ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, |
659 | ERR_R_NESTED_ASN1_ERROR); | 659 | ERR_R_NESTED_ASN1_ERROR); |
660 | return 0; | 660 | return 0; |
661 | } | 661 | } |
662 | else if (ret == -1) | 662 | else if (ret == -1) |
663 | return -1; | 663 | return -1; |
664 | if (!*val) | 664 | if (!*val) |
665 | *val = (ASN1_VALUE *)sk_new_null(); | 665 | *val = (ASN1_VALUE *)sk_new_null(); |
666 | else | 666 | else |
667 | { | 667 | { |
668 | /* We've got a valid STACK: free up any items present */ | 668 | /* We've got a valid STACK: free up any items present */ |
669 | STACK_OF(ASN1_VALUE) *sktmp | 669 | STACK_OF(ASN1_VALUE) *sktmp |
670 | = (STACK_OF(ASN1_VALUE) *)*val; | 670 | = (STACK_OF(ASN1_VALUE) *)*val; |
671 | ASN1_VALUE *vtmp; | 671 | ASN1_VALUE *vtmp; |
672 | while(sk_ASN1_VALUE_num(sktmp) > 0) | 672 | while(sk_ASN1_VALUE_num(sktmp) > 0) |
673 | { | 673 | { |
674 | vtmp = sk_ASN1_VALUE_pop(sktmp); | 674 | vtmp = sk_ASN1_VALUE_pop(sktmp); |
675 | ASN1_item_ex_free(&vtmp, | 675 | ASN1_item_ex_free(&vtmp, |
676 | ASN1_ITEM_ptr(tt->item)); | 676 | ASN1_ITEM_ptr(tt->item)); |
677 | } | ||
678 | } | 677 | } |
678 | } | ||
679 | 679 | ||
680 | if (!*val) | 680 | if (!*val) |
681 | { | 681 | { |
682 | ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, | 682 | ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, |
683 | ERR_R_MALLOC_FAILURE); | 683 | ERR_R_MALLOC_FAILURE); |
684 | goto err; | 684 | goto err; |
685 | } | 685 | } |
686 | 686 | ||
687 | /* Read as many items as we can */ | 687 | /* Read as many items as we can */ |
688 | while(len > 0) | 688 | while(len > 0) |
689 | { | 689 | { |
690 | ASN1_VALUE *skfield; | 690 | ASN1_VALUE *skfield; |
691 | q = p; | 691 | q = p; |
692 | /* See if EOC found */ | 692 | /* See if EOC found */ |
693 | if (asn1_check_eoc(&p, len)) | 693 | if (asn1_check_eoc(&p, len)) |
694 | { | 694 | { |
695 | if (!sk_eoc) | 695 | if (!sk_eoc) |
696 | { | 696 | { |
697 | ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, | 697 | ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, |
698 | ASN1_R_UNEXPECTED_EOC); | 698 | ASN1_R_UNEXPECTED_EOC); |
699 | goto err; | 699 | goto err; |
700 | } | 700 | } |
701 | len -= p - q; | 701 | len -= p - q; |
702 | sk_eoc = 0; | 702 | sk_eoc = 0; |
703 | break; | 703 | break; |
704 | } | 704 | } |
705 | skfield = NULL; | 705 | skfield = NULL; |
706 | if (!ASN1_item_ex_d2i(&skfield, &p, len, | 706 | if (!ASN1_item_ex_d2i(&skfield, &p, len, |
707 | ASN1_ITEM_ptr(tt->item), | 707 | ASN1_ITEM_ptr(tt->item), |
708 | -1, 0, 0, ctx)) | 708 | -1, 0, 0, ctx)) |
709 | { | 709 | { |
710 | ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, | 710 | ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, |
711 | ERR_R_NESTED_ASN1_ERROR); | 711 | ERR_R_NESTED_ASN1_ERROR); |
712 | goto err; | 712 | goto err; |
713 | } | 713 | } |
714 | len -= p - q; | 714 | len -= p - q; |
715 | if (!sk_ASN1_VALUE_push((STACK_OF(ASN1_VALUE) *)*val, | 715 | if (!sk_ASN1_VALUE_push((STACK_OF(ASN1_VALUE) *)*val, |
716 | skfield)) | 716 | skfield)) |
717 | { | 717 | { |
718 | ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, | 718 | ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, |
719 | ERR_R_MALLOC_FAILURE); | 719 | ERR_R_MALLOC_FAILURE); |
720 | goto err; | 720 | goto err; |
721 | } | ||
722 | } | 721 | } |
722 | } | ||
723 | if (sk_eoc) | 723 | if (sk_eoc) |
724 | { | 724 | { |
725 | ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, ASN1_R_MISSING_EOC); | 725 | ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, ASN1_R_MISSING_EOC); |
726 | goto err; | 726 | goto err; |
727 | } | ||
728 | } | 727 | } |
728 | } | ||
729 | else if (flags & ASN1_TFLG_IMPTAG) | 729 | else if (flags & ASN1_TFLG_IMPTAG) |
730 | { | 730 | { |
731 | /* IMPLICIT tagging */ | 731 | /* IMPLICIT tagging */ |
732 | ret = ASN1_item_ex_d2i(val, &p, len, | 732 | ret = ASN1_item_ex_d2i(val, &p, len, |
733 | ASN1_ITEM_ptr(tt->item), tt->tag, aclass, opt, ctx); | 733 | ASN1_ITEM_ptr(tt->item), tt->tag, aclass, opt, ctx); |
734 | if (!ret) | 734 | if (!ret) |
735 | { | 735 | { |
736 | ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, | 736 | ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, |
737 | ERR_R_NESTED_ASN1_ERROR); | 737 | ERR_R_NESTED_ASN1_ERROR); |
738 | goto err; | 738 | goto err; |
739 | } | 739 | } |
740 | else if (ret == -1) | 740 | else if (ret == -1) |
741 | return -1; | 741 | return -1; |
742 | } | 742 | } |
743 | else | 743 | else |
744 | { | 744 | { |
745 | /* Nothing special */ | 745 | /* Nothing special */ |
746 | ret = ASN1_item_ex_d2i(val, &p, len, ASN1_ITEM_ptr(tt->item), | 746 | ret = ASN1_item_ex_d2i(val, &p, len, ASN1_ITEM_ptr(tt->item), |
747 | -1, 0, opt, ctx); | 747 | -1, 0, opt, ctx); |
748 | if (!ret) | 748 | if (!ret) |
749 | { | 749 | { |
750 | ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, | 750 | ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, |
751 | ERR_R_NESTED_ASN1_ERROR); | 751 | ERR_R_NESTED_ASN1_ERROR); |
752 | goto err; | 752 | goto err; |
753 | } | 753 | } |
754 | else if (ret == -1) | 754 | else if (ret == -1) |
755 | return -1; | 755 | return -1; |
756 | } | 756 | } |
757 | 757 | ||
758 | *in = p; | 758 | *in = p; |
759 | return 1; | 759 | return 1; |
@@ -761,13 +761,13 @@ static int asn1_template_noexp_d2i(ASN1_VALUE **val, | |||
761 | err: | 761 | err: |
762 | ASN1_template_free(val, tt); | 762 | ASN1_template_free(val, tt); |
763 | return 0; | 763 | return 0; |
764 | } | 764 | } |
765 | 765 | ||
766 | static int asn1_d2i_ex_primitive(ASN1_VALUE **pval, | 766 | static int asn1_d2i_ex_primitive(ASN1_VALUE **pval, |
767 | const unsigned char **in, long inlen, | 767 | const unsigned char **in, long inlen, |
768 | const ASN1_ITEM *it, | 768 | const ASN1_ITEM *it, |
769 | int tag, int aclass, char opt, ASN1_TLC *ctx) | 769 | int tag, int aclass, char opt, ASN1_TLC *ctx) |
770 | { | 770 | { |
771 | int ret = 0, utype; | 771 | int ret = 0, utype; |
772 | long plen; | 772 | long plen; |
773 | char cst, inf, free_cont = 0; | 773 | char cst, inf, free_cont = 0; |
@@ -776,100 +776,100 @@ static int asn1_d2i_ex_primitive(ASN1_VALUE **pval, | |||
776 | const unsigned char *cont = NULL; | 776 | const unsigned char *cont = NULL; |
777 | long len; | 777 | long len; |
778 | if (!pval) | 778 | if (!pval) |
779 | { | 779 | { |
780 | ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ASN1_R_ILLEGAL_NULL); | 780 | ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ASN1_R_ILLEGAL_NULL); |
781 | return 0; /* Should never happen */ | 781 | return 0; /* Should never happen */ |
782 | } | 782 | } |
783 | 783 | ||
784 | if (it->itype == ASN1_ITYPE_MSTRING) | 784 | if (it->itype == ASN1_ITYPE_MSTRING) |
785 | { | 785 | { |
786 | utype = tag; | 786 | utype = tag; |
787 | tag = -1; | 787 | tag = -1; |
788 | } | 788 | } |
789 | else | 789 | else |
790 | utype = it->utype; | 790 | utype = it->utype; |
791 | 791 | ||
792 | if (utype == V_ASN1_ANY) | 792 | if (utype == V_ASN1_ANY) |
793 | { | 793 | { |
794 | /* If type is ANY need to figure out type from tag */ | 794 | /* If type is ANY need to figure out type from tag */ |
795 | unsigned char oclass; | 795 | unsigned char oclass; |
796 | if (tag >= 0) | 796 | if (tag >= 0) |
797 | { | 797 | { |
798 | ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, | 798 | ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, |
799 | ASN1_R_ILLEGAL_TAGGED_ANY); | 799 | ASN1_R_ILLEGAL_TAGGED_ANY); |
800 | return 0; | 800 | return 0; |
801 | } | 801 | } |
802 | if (opt) | 802 | if (opt) |
803 | { | 803 | { |
804 | ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, | 804 | ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, |
805 | ASN1_R_ILLEGAL_OPTIONAL_ANY); | 805 | ASN1_R_ILLEGAL_OPTIONAL_ANY); |
806 | return 0; | 806 | return 0; |
807 | } | 807 | } |
808 | p = *in; | 808 | p = *in; |
809 | ret = asn1_check_tlen(NULL, &utype, &oclass, NULL, NULL, | 809 | ret = asn1_check_tlen(NULL, &utype, &oclass, NULL, NULL, |
810 | &p, inlen, -1, 0, 0, ctx); | 810 | &p, inlen, -1, 0, 0, ctx); |
811 | if (!ret) | 811 | if (!ret) |
812 | { | 812 | { |
813 | ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, | 813 | ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, |
814 | ERR_R_NESTED_ASN1_ERROR); | 814 | ERR_R_NESTED_ASN1_ERROR); |
815 | return 0; | 815 | return 0; |
816 | } | 816 | } |
817 | if (oclass != V_ASN1_UNIVERSAL) | 817 | if (oclass != V_ASN1_UNIVERSAL) |
818 | utype = V_ASN1_OTHER; | 818 | utype = V_ASN1_OTHER; |
819 | } | 819 | } |
820 | if (tag == -1) | 820 | if (tag == -1) |
821 | { | 821 | { |
822 | tag = utype; | 822 | tag = utype; |
823 | aclass = V_ASN1_UNIVERSAL; | 823 | aclass = V_ASN1_UNIVERSAL; |
824 | } | 824 | } |
825 | p = *in; | 825 | p = *in; |
826 | /* Check header */ | 826 | /* Check header */ |
827 | ret = asn1_check_tlen(&plen, NULL, NULL, &inf, &cst, | 827 | ret = asn1_check_tlen(&plen, NULL, NULL, &inf, &cst, |
828 | &p, inlen, tag, aclass, opt, ctx); | 828 | &p, inlen, tag, aclass, opt, ctx); |
829 | if (!ret) | 829 | if (!ret) |
830 | { | 830 | { |
831 | ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ERR_R_NESTED_ASN1_ERROR); | 831 | ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ERR_R_NESTED_ASN1_ERROR); |
832 | return 0; | 832 | return 0; |
833 | } | 833 | } |
834 | else if (ret == -1) | 834 | else if (ret == -1) |
835 | return -1; | 835 | return -1; |
836 | ret = 0; | 836 | ret = 0; |
837 | /* SEQUENCE, SET and "OTHER" are left in encoded form */ | 837 | /* SEQUENCE, SET and "OTHER" are left in encoded form */ |
838 | if ((utype == V_ASN1_SEQUENCE) | 838 | if ((utype == V_ASN1_SEQUENCE) |
839 | || (utype == V_ASN1_SET) || (utype == V_ASN1_OTHER)) | 839 | || (utype == V_ASN1_SET) || (utype == V_ASN1_OTHER)) |
840 | { | 840 | { |
841 | /* Clear context cache for type OTHER because the auto clear | 841 | /* Clear context cache for type OTHER because the auto clear |
842 | * when we have a exact match wont work | 842 | * when we have a exact match wont work |
843 | */ | 843 | */ |
844 | if (utype == V_ASN1_OTHER) | 844 | if (utype == V_ASN1_OTHER) |
845 | { | 845 | { |
846 | asn1_tlc_clear(ctx); | 846 | asn1_tlc_clear(ctx); |
847 | } | 847 | } |
848 | /* SEQUENCE and SET must be constructed */ | 848 | /* SEQUENCE and SET must be constructed */ |
849 | else if (!cst) | 849 | else if (!cst) |
850 | { | 850 | { |
851 | ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, | 851 | ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, |
852 | ASN1_R_TYPE_NOT_CONSTRUCTED); | 852 | ASN1_R_TYPE_NOT_CONSTRUCTED); |
853 | return 0; | 853 | return 0; |
854 | } | 854 | } |
855 | 855 | ||
856 | cont = *in; | 856 | cont = *in; |
857 | /* If indefinite length constructed find the real end */ | 857 | /* If indefinite length constructed find the real end */ |
858 | if (inf) | 858 | if (inf) |
859 | { | 859 | { |
860 | if (!asn1_find_end(&p, plen, inf)) | 860 | if (!asn1_find_end(&p, plen, inf)) |
861 | goto err; | 861 | goto err; |
862 | len = p - cont; | 862 | len = p - cont; |
863 | } | 863 | } |
864 | else | 864 | else |
865 | { | 865 | { |
866 | len = p - cont + plen; | 866 | len = p - cont + plen; |
867 | p += plen; | 867 | p += plen; |
868 | buf.data = NULL; | 868 | buf.data = NULL; |
869 | } | ||
870 | } | 869 | } |
870 | } | ||
871 | else if (cst) | 871 | else if (cst) |
872 | { | 872 | { |
873 | buf.length = 0; | 873 | buf.length = 0; |
874 | buf.max = 0; | 874 | buf.max = 0; |
875 | buf.data = NULL; | 875 | buf.data = NULL; |
@@ -880,28 +880,28 @@ static int asn1_d2i_ex_primitive(ASN1_VALUE **pval, | |||
880 | * for UNIVERSAL class and ignore the tag. | 880 | * for UNIVERSAL class and ignore the tag. |
881 | */ | 881 | */ |
882 | if (!asn1_collect(&buf, &p, plen, inf, -1, V_ASN1_UNIVERSAL, 0)) | 882 | if (!asn1_collect(&buf, &p, plen, inf, -1, V_ASN1_UNIVERSAL, 0)) |
883 | { | 883 | { |
884 | free_cont = 1; | 884 | free_cont = 1; |
885 | goto err; | 885 | goto err; |
886 | } | 886 | } |
887 | len = buf.length; | 887 | len = buf.length; |
888 | /* Append a final null to string */ | 888 | /* Append a final null to string */ |
889 | if (!BUF_MEM_grow_clean(&buf, len + 1)) | 889 | if (!BUF_MEM_grow_clean(&buf, len + 1)) |
890 | { | 890 | { |
891 | ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, | 891 | ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, |
892 | ERR_R_MALLOC_FAILURE); | 892 | ERR_R_MALLOC_FAILURE); |
893 | return 0; | 893 | return 0; |
894 | } | 894 | } |
895 | buf.data[len] = 0; | 895 | buf.data[len] = 0; |
896 | cont = (const unsigned char *)buf.data; | 896 | cont = (const unsigned char *)buf.data; |
897 | free_cont = 1; | 897 | free_cont = 1; |
898 | } | 898 | } |
899 | else | 899 | else |
900 | { | 900 | { |
901 | cont = p; | 901 | cont = p; |
902 | len = plen; | 902 | len = plen; |
903 | p += plen; | 903 | p += plen; |
904 | } | 904 | } |
905 | 905 | ||
906 | /* We now have content length and type: translate into a structure */ | 906 | /* We now have content length and type: translate into a structure */ |
907 | if (!asn1_ex_c2i(pval, cont, len, utype, &free_cont, it)) | 907 | if (!asn1_ex_c2i(pval, cont, len, utype, &free_cont, it)) |
@@ -912,13 +912,13 @@ static int asn1_d2i_ex_primitive(ASN1_VALUE **pval, | |||
912 | err: | 912 | err: |
913 | if (free_cont && buf.data) free(buf.data); | 913 | if (free_cont && buf.data) free(buf.data); |
914 | return ret; | 914 | return ret; |
915 | } | 915 | } |
916 | 916 | ||
917 | /* Translate ASN1 content octets into a structure */ | 917 | /* Translate ASN1 content octets into a structure */ |
918 | 918 | ||
919 | int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, | 919 | int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, |
920 | int utype, char *free_cont, const ASN1_ITEM *it) | 920 | int utype, char *free_cont, const ASN1_ITEM *it) |
921 | { | 921 | { |
922 | ASN1_VALUE **opval = NULL; | 922 | ASN1_VALUE **opval = NULL; |
923 | ASN1_STRING *stmp; | 923 | ASN1_STRING *stmp; |
924 | ASN1_TYPE *typ = NULL; | 924 | ASN1_TYPE *typ = NULL; |
@@ -931,14 +931,14 @@ int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, | |||
931 | return pf->prim_c2i(pval, cont, len, utype, free_cont, it); | 931 | return pf->prim_c2i(pval, cont, len, utype, free_cont, it); |
932 | /* If ANY type clear type and set pointer to internal value */ | 932 | /* If ANY type clear type and set pointer to internal value */ |
933 | if (it->utype == V_ASN1_ANY) | 933 | if (it->utype == V_ASN1_ANY) |
934 | { | 934 | { |
935 | if (!*pval) | 935 | if (!*pval) |
936 | { | 936 | { |
937 | typ = ASN1_TYPE_new(); | 937 | typ = ASN1_TYPE_new(); |
938 | if (typ == NULL) | 938 | if (typ == NULL) |
939 | goto err; | 939 | goto err; |
940 | *pval = (ASN1_VALUE *)typ; | 940 | *pval = (ASN1_VALUE *)typ; |
941 | } | 941 | } |
942 | else | 942 | else |
943 | typ = (ASN1_TYPE *)*pval; | 943 | typ = (ASN1_TYPE *)*pval; |
944 | 944 | ||
@@ -946,9 +946,9 @@ int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, | |||
946 | ASN1_TYPE_set(typ, utype, NULL); | 946 | ASN1_TYPE_set(typ, utype, NULL); |
947 | opval = pval; | 947 | opval = pval; |
948 | pval = &typ->value.asn1_value; | 948 | pval = &typ->value.asn1_value; |
949 | } | 949 | } |
950 | switch(utype) | 950 | switch(utype) |
951 | { | 951 | { |
952 | case V_ASN1_OBJECT: | 952 | case V_ASN1_OBJECT: |
953 | if (!c2i_ASN1_OBJECT((ASN1_OBJECT **)pval, &cont, len)) | 953 | if (!c2i_ASN1_OBJECT((ASN1_OBJECT **)pval, &cont, len)) |
954 | goto err; | 954 | goto err; |
@@ -956,27 +956,27 @@ int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, | |||
956 | 956 | ||
957 | case V_ASN1_NULL: | 957 | case V_ASN1_NULL: |
958 | if (len) | 958 | if (len) |
959 | { | 959 | { |
960 | ASN1err(ASN1_F_ASN1_EX_C2I, | 960 | ASN1err(ASN1_F_ASN1_EX_C2I, |
961 | ASN1_R_NULL_IS_WRONG_LENGTH); | 961 | ASN1_R_NULL_IS_WRONG_LENGTH); |
962 | goto err; | 962 | goto err; |
963 | } | 963 | } |
964 | *pval = (ASN1_VALUE *)1; | 964 | *pval = (ASN1_VALUE *)1; |
965 | break; | 965 | break; |
966 | 966 | ||
967 | case V_ASN1_BOOLEAN: | 967 | case V_ASN1_BOOLEAN: |
968 | if (len != 1) | 968 | if (len != 1) |
969 | { | 969 | { |
970 | ASN1err(ASN1_F_ASN1_EX_C2I, | 970 | ASN1err(ASN1_F_ASN1_EX_C2I, |
971 | ASN1_R_BOOLEAN_IS_WRONG_LENGTH); | 971 | ASN1_R_BOOLEAN_IS_WRONG_LENGTH); |
972 | goto err; | 972 | goto err; |
973 | } | 973 | } |
974 | else | 974 | else |
975 | { | 975 | { |
976 | ASN1_BOOLEAN *tbool; | 976 | ASN1_BOOLEAN *tbool; |
977 | tbool = (ASN1_BOOLEAN *)pval; | 977 | tbool = (ASN1_BOOLEAN *)pval; |
978 | *tbool = *cont; | 978 | *tbool = *cont; |
979 | } | 979 | } |
980 | break; | 980 | break; |
981 | 981 | ||
982 | case V_ASN1_BIT_STRING: | 982 | case V_ASN1_BIT_STRING: |
@@ -1014,56 +1014,56 @@ int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, | |||
1014 | case V_ASN1_SEQUENCE: | 1014 | case V_ASN1_SEQUENCE: |
1015 | default: | 1015 | default: |
1016 | if (utype == V_ASN1_BMPSTRING && (len & 1)) | 1016 | if (utype == V_ASN1_BMPSTRING && (len & 1)) |
1017 | { | 1017 | { |
1018 | ASN1err(ASN1_F_ASN1_EX_C2I, | 1018 | ASN1err(ASN1_F_ASN1_EX_C2I, |
1019 | ASN1_R_BMPSTRING_IS_WRONG_LENGTH); | 1019 | ASN1_R_BMPSTRING_IS_WRONG_LENGTH); |
1020 | goto err; | 1020 | goto err; |
1021 | } | 1021 | } |
1022 | if (utype == V_ASN1_UNIVERSALSTRING && (len & 3)) | 1022 | if (utype == V_ASN1_UNIVERSALSTRING && (len & 3)) |
1023 | { | 1023 | { |
1024 | ASN1err(ASN1_F_ASN1_EX_C2I, | 1024 | ASN1err(ASN1_F_ASN1_EX_C2I, |
1025 | ASN1_R_UNIVERSALSTRING_IS_WRONG_LENGTH); | 1025 | ASN1_R_UNIVERSALSTRING_IS_WRONG_LENGTH); |
1026 | goto err; | 1026 | goto err; |
1027 | } | 1027 | } |
1028 | /* All based on ASN1_STRING and handled the same */ | 1028 | /* All based on ASN1_STRING and handled the same */ |
1029 | if (!*pval) | 1029 | if (!*pval) |
1030 | { | 1030 | { |
1031 | stmp = ASN1_STRING_type_new(utype); | 1031 | stmp = ASN1_STRING_type_new(utype); |
1032 | if (!stmp) | 1032 | if (!stmp) |
1033 | { | 1033 | { |
1034 | ASN1err(ASN1_F_ASN1_EX_C2I, | 1034 | ASN1err(ASN1_F_ASN1_EX_C2I, |
1035 | ERR_R_MALLOC_FAILURE); | 1035 | ERR_R_MALLOC_FAILURE); |
1036 | goto err; | 1036 | goto err; |
1037 | } | ||
1038 | *pval = (ASN1_VALUE *)stmp; | ||
1039 | } | 1037 | } |
1038 | *pval = (ASN1_VALUE *)stmp; | ||
1039 | } | ||
1040 | else | 1040 | else |
1041 | { | 1041 | { |
1042 | stmp = (ASN1_STRING *)*pval; | 1042 | stmp = (ASN1_STRING *)*pval; |
1043 | stmp->type = utype; | 1043 | stmp->type = utype; |
1044 | } | 1044 | } |
1045 | /* If we've already allocated a buffer use it */ | 1045 | /* If we've already allocated a buffer use it */ |
1046 | if (*free_cont) | 1046 | if (*free_cont) |
1047 | { | 1047 | { |
1048 | if (stmp->data) | 1048 | if (stmp->data) |
1049 | free(stmp->data); | 1049 | free(stmp->data); |
1050 | stmp->data = (unsigned char *)cont; /* UGLY CAST! RL */ | 1050 | stmp->data = (unsigned char *)cont; /* UGLY CAST! RL */ |
1051 | stmp->length = len; | 1051 | stmp->length = len; |
1052 | *free_cont = 0; | 1052 | *free_cont = 0; |
1053 | } | 1053 | } |
1054 | else | 1054 | else |
1055 | { | 1055 | { |
1056 | if (!ASN1_STRING_set(stmp, cont, len)) | 1056 | if (!ASN1_STRING_set(stmp, cont, len)) |
1057 | { | 1057 | { |
1058 | ASN1err(ASN1_F_ASN1_EX_C2I, | 1058 | ASN1err(ASN1_F_ASN1_EX_C2I, |
1059 | ERR_R_MALLOC_FAILURE); | 1059 | ERR_R_MALLOC_FAILURE); |
1060 | ASN1_STRING_free(stmp); | 1060 | ASN1_STRING_free(stmp); |
1061 | *pval = NULL; | 1061 | *pval = NULL; |
1062 | goto err; | 1062 | goto err; |
1063 | } | ||
1064 | } | 1063 | } |
1065 | break; | ||
1066 | } | 1064 | } |
1065 | break; | ||
1066 | } | ||
1067 | /* If ASN1_ANY and NULL type fix up value */ | 1067 | /* If ASN1_ANY and NULL type fix up value */ |
1068 | if (typ && (utype == V_ASN1_NULL)) | 1068 | if (typ && (utype == V_ASN1_NULL)) |
1069 | typ->value.ptr = NULL; | 1069 | typ->value.ptr = NULL; |
@@ -1071,13 +1071,13 @@ int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, | |||
1071 | ret = 1; | 1071 | ret = 1; |
1072 | err: | 1072 | err: |
1073 | if (!ret) | 1073 | if (!ret) |
1074 | { | 1074 | { |
1075 | ASN1_TYPE_free(typ); | 1075 | ASN1_TYPE_free(typ); |
1076 | if (opval) | 1076 | if (opval) |
1077 | *opval = NULL; | 1077 | *opval = NULL; |
1078 | } | ||
1079 | return ret; | ||
1080 | } | 1078 | } |
1079 | return ret; | ||
1080 | } | ||
1081 | 1081 | ||
1082 | 1082 | ||
1083 | /* This function finds the end of an ASN1 structure when passed its maximum | 1083 | /* This function finds the end of an ASN1 structure when passed its maximum |
@@ -1087,16 +1087,16 @@ int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, | |||
1087 | */ | 1087 | */ |
1088 | 1088 | ||
1089 | static int asn1_find_end(const unsigned char **in, long len, char inf) | 1089 | static int asn1_find_end(const unsigned char **in, long len, char inf) |
1090 | { | 1090 | { |
1091 | int expected_eoc; | 1091 | int expected_eoc; |
1092 | long plen; | 1092 | long plen; |
1093 | const unsigned char *p = *in, *q; | 1093 | const unsigned char *p = *in, *q; |
1094 | /* If not indefinite length constructed just add length */ | 1094 | /* If not indefinite length constructed just add length */ |
1095 | if (inf == 0) | 1095 | if (inf == 0) |
1096 | { | 1096 | { |
1097 | *in += len; | 1097 | *in += len; |
1098 | return 1; | 1098 | return 1; |
1099 | } | 1099 | } |
1100 | expected_eoc = 1; | 1100 | expected_eoc = 1; |
1101 | /* Indefinite length constructed form. Find the end when enough EOCs | 1101 | /* Indefinite length constructed form. Find the end when enough EOCs |
1102 | * are found. If more indefinite length constructed headers | 1102 | * are found. If more indefinite length constructed headers |
@@ -1104,37 +1104,37 @@ static int asn1_find_end(const unsigned char **in, long len, char inf) | |||
1104 | * skip to the end of the data. | 1104 | * skip to the end of the data. |
1105 | */ | 1105 | */ |
1106 | while (len > 0) | 1106 | while (len > 0) |
1107 | { | 1107 | { |
1108 | if(asn1_check_eoc(&p, len)) | 1108 | if(asn1_check_eoc(&p, len)) |
1109 | { | 1109 | { |
1110 | expected_eoc--; | 1110 | expected_eoc--; |
1111 | if (expected_eoc == 0) | 1111 | if (expected_eoc == 0) |
1112 | break; | 1112 | break; |
1113 | len -= 2; | 1113 | len -= 2; |
1114 | continue; | 1114 | continue; |
1115 | } | 1115 | } |
1116 | q = p; | 1116 | q = p; |
1117 | /* Just read in a header: only care about the length */ | 1117 | /* Just read in a header: only care about the length */ |
1118 | if(!asn1_check_tlen(&plen, NULL, NULL, &inf, NULL, &p, len, | 1118 | if(!asn1_check_tlen(&plen, NULL, NULL, &inf, NULL, &p, len, |
1119 | -1, 0, 0, NULL)) | 1119 | -1, 0, 0, NULL)) |
1120 | { | 1120 | { |
1121 | ASN1err(ASN1_F_ASN1_FIND_END, ERR_R_NESTED_ASN1_ERROR); | 1121 | ASN1err(ASN1_F_ASN1_FIND_END, ERR_R_NESTED_ASN1_ERROR); |
1122 | return 0; | 1122 | return 0; |
1123 | } | 1123 | } |
1124 | if (inf) | 1124 | if (inf) |
1125 | expected_eoc++; | 1125 | expected_eoc++; |
1126 | else | 1126 | else |
1127 | p += plen; | 1127 | p += plen; |
1128 | len -= p - q; | 1128 | len -= p - q; |
1129 | } | 1129 | } |
1130 | if (expected_eoc) | 1130 | if (expected_eoc) |
1131 | { | 1131 | { |
1132 | ASN1err(ASN1_F_ASN1_FIND_END, ASN1_R_MISSING_EOC); | 1132 | ASN1err(ASN1_F_ASN1_FIND_END, ASN1_R_MISSING_EOC); |
1133 | return 0; | 1133 | return 0; |
1134 | } | 1134 | } |
1135 | *in = p; | 1135 | *in = p; |
1136 | return 1; | 1136 | return 1; |
1137 | } | 1137 | } |
1138 | /* This function collects the asn1 data from a constructred string | 1138 | /* This function collects the asn1 data from a constructred string |
1139 | * type into a buffer. The values of 'in' and 'len' should refer | 1139 | * type into a buffer. The values of 'in' and 'len' should refer |
1140 | * to the contents of the constructed type and 'inf' should be set | 1140 | * to the contents of the constructed type and 'inf' should be set |
@@ -1153,7 +1153,7 @@ static int asn1_find_end(const unsigned char **in, long len, char inf) | |||
1153 | 1153 | ||
1154 | static int asn1_collect(BUF_MEM *buf, const unsigned char **in, long len, | 1154 | static int asn1_collect(BUF_MEM *buf, const unsigned char **in, long len, |
1155 | char inf, int tag, int aclass, int depth) | 1155 | char inf, int tag, int aclass, int depth) |
1156 | { | 1156 | { |
1157 | const unsigned char *p, *q; | 1157 | const unsigned char *p, *q; |
1158 | long plen; | 1158 | long plen; |
1159 | char cst, ininf; | 1159 | char cst, ininf; |
@@ -1162,92 +1162,92 @@ static int asn1_collect(BUF_MEM *buf, const unsigned char **in, long len, | |||
1162 | /* If no buffer and not indefinite length constructed just pass over | 1162 | /* If no buffer and not indefinite length constructed just pass over |
1163 | * the encoded data */ | 1163 | * the encoded data */ |
1164 | if (!buf && !inf) | 1164 | if (!buf && !inf) |
1165 | { | 1165 | { |
1166 | *in += len; | 1166 | *in += len; |
1167 | return 1; | 1167 | return 1; |
1168 | } | 1168 | } |
1169 | while(len > 0) | 1169 | while(len > 0) |
1170 | { | 1170 | { |
1171 | q = p; | 1171 | q = p; |
1172 | /* Check for EOC */ | 1172 | /* Check for EOC */ |
1173 | if (asn1_check_eoc(&p, len)) | 1173 | if (asn1_check_eoc(&p, len)) |
1174 | { | 1174 | { |
1175 | /* EOC is illegal outside indefinite length | 1175 | /* EOC is illegal outside indefinite length |
1176 | * constructed form */ | 1176 | * constructed form */ |
1177 | if (!inf) | 1177 | if (!inf) |
1178 | { | 1178 | { |
1179 | ASN1err(ASN1_F_ASN1_COLLECT, | 1179 | ASN1err(ASN1_F_ASN1_COLLECT, |
1180 | ASN1_R_UNEXPECTED_EOC); | 1180 | ASN1_R_UNEXPECTED_EOC); |
1181 | return 0; | 1181 | return 0; |
1182 | } | 1182 | } |
1183 | inf = 0; | 1183 | inf = 0; |
1184 | break; | 1184 | break; |
1185 | } | 1185 | } |
1186 | 1186 | ||
1187 | if (!asn1_check_tlen(&plen, NULL, NULL, &ininf, &cst, &p, | 1187 | if (!asn1_check_tlen(&plen, NULL, NULL, &ininf, &cst, &p, |
1188 | len, tag, aclass, 0, NULL)) | 1188 | len, tag, aclass, 0, NULL)) |
1189 | { | 1189 | { |
1190 | ASN1err(ASN1_F_ASN1_COLLECT, ERR_R_NESTED_ASN1_ERROR); | 1190 | ASN1err(ASN1_F_ASN1_COLLECT, ERR_R_NESTED_ASN1_ERROR); |
1191 | return 0; | 1191 | return 0; |
1192 | } | 1192 | } |
1193 | 1193 | ||
1194 | /* If indefinite length constructed update max length */ | 1194 | /* If indefinite length constructed update max length */ |
1195 | if (cst) | 1195 | if (cst) |
1196 | { | 1196 | { |
1197 | if (depth >= ASN1_MAX_STRING_NEST) | 1197 | if (depth >= ASN1_MAX_STRING_NEST) |
1198 | { | 1198 | { |
1199 | ASN1err(ASN1_F_ASN1_COLLECT, | 1199 | ASN1err(ASN1_F_ASN1_COLLECT, |
1200 | ASN1_R_NESTED_ASN1_STRING); | 1200 | ASN1_R_NESTED_ASN1_STRING); |
1201 | return 0; | 1201 | return 0; |
1202 | } | 1202 | } |
1203 | if (!asn1_collect(buf, &p, plen, ininf, tag, aclass, | 1203 | if (!asn1_collect(buf, &p, plen, ininf, tag, aclass, |
1204 | depth + 1)) | 1204 | depth + 1)) |
1205 | return 0; | 1205 | return 0; |
1206 | } | 1206 | } |
1207 | else if (plen && !collect_data(buf, &p, plen)) | 1207 | else if (plen && !collect_data(buf, &p, plen)) |
1208 | return 0; | 1208 | return 0; |
1209 | len -= p - q; | 1209 | len -= p - q; |
1210 | } | 1210 | } |
1211 | if (inf) | 1211 | if (inf) |
1212 | { | 1212 | { |
1213 | ASN1err(ASN1_F_ASN1_COLLECT, ASN1_R_MISSING_EOC); | 1213 | ASN1err(ASN1_F_ASN1_COLLECT, ASN1_R_MISSING_EOC); |
1214 | return 0; | 1214 | return 0; |
1215 | } | 1215 | } |
1216 | *in = p; | 1216 | *in = p; |
1217 | return 1; | 1217 | return 1; |
1218 | } | 1218 | } |
1219 | 1219 | ||
1220 | static int collect_data(BUF_MEM *buf, const unsigned char **p, long plen) | 1220 | static int collect_data(BUF_MEM *buf, const unsigned char **p, long plen) |
1221 | { | 1221 | { |
1222 | int len; | 1222 | int len; |
1223 | if (buf) | 1223 | if (buf) |
1224 | { | 1224 | { |
1225 | len = buf->length; | 1225 | len = buf->length; |
1226 | if (!BUF_MEM_grow_clean(buf, len + plen)) | 1226 | if (!BUF_MEM_grow_clean(buf, len + plen)) |
1227 | { | 1227 | { |
1228 | ASN1err(ASN1_F_COLLECT_DATA, ERR_R_MALLOC_FAILURE); | 1228 | ASN1err(ASN1_F_COLLECT_DATA, ERR_R_MALLOC_FAILURE); |
1229 | return 0; | 1229 | return 0; |
1230 | } | ||
1231 | memcpy(buf->data + len, *p, plen); | ||
1232 | } | 1230 | } |
1231 | memcpy(buf->data + len, *p, plen); | ||
1232 | } | ||
1233 | *p += plen; | 1233 | *p += plen; |
1234 | return 1; | 1234 | return 1; |
1235 | } | 1235 | } |
1236 | 1236 | ||
1237 | /* Check for ASN1 EOC and swallow it if found */ | 1237 | /* Check for ASN1 EOC and swallow it if found */ |
1238 | 1238 | ||
1239 | static int asn1_check_eoc(const unsigned char **in, long len) | 1239 | static int asn1_check_eoc(const unsigned char **in, long len) |
1240 | { | 1240 | { |
1241 | const unsigned char *p; | 1241 | const unsigned char *p; |
1242 | if (len < 2) return 0; | 1242 | if (len < 2) return 0; |
1243 | p = *in; | 1243 | p = *in; |
1244 | if (!p[0] && !p[1]) | 1244 | if (!p[0] && !p[1]) |
1245 | { | 1245 | { |
1246 | *in += 2; | 1246 | *in += 2; |
1247 | return 1; | 1247 | return 1; |
1248 | } | ||
1249 | return 0; | ||
1250 | } | 1248 | } |
1249 | return 0; | ||
1250 | } | ||
1251 | 1251 | ||
1252 | /* Check an ASN1 tag and length: a bit like ASN1_get_object | 1252 | /* Check an ASN1 tag and length: a bit like ASN1_get_object |
1253 | * but it sets the length for indefinite length constructed | 1253 | * but it sets the length for indefinite length constructed |
@@ -1261,7 +1261,7 @@ static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass, | |||
1261 | const unsigned char **in, long len, | 1261 | const unsigned char **in, long len, |
1262 | int exptag, int expclass, char opt, | 1262 | int exptag, int expclass, char opt, |
1263 | ASN1_TLC *ctx) | 1263 | ASN1_TLC *ctx) |
1264 | { | 1264 | { |
1265 | int i; | 1265 | int i; |
1266 | int ptag, pclass; | 1266 | int ptag, pclass; |
1267 | long plen; | 1267 | long plen; |
@@ -1270,18 +1270,18 @@ static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass, | |||
1270 | q = p; | 1270 | q = p; |
1271 | 1271 | ||
1272 | if (ctx && ctx->valid) | 1272 | if (ctx && ctx->valid) |
1273 | { | 1273 | { |
1274 | i = ctx->ret; | 1274 | i = ctx->ret; |
1275 | plen = ctx->plen; | 1275 | plen = ctx->plen; |
1276 | pclass = ctx->pclass; | 1276 | pclass = ctx->pclass; |
1277 | ptag = ctx->ptag; | 1277 | ptag = ctx->ptag; |
1278 | p += ctx->hdrlen; | 1278 | p += ctx->hdrlen; |
1279 | } | 1279 | } |
1280 | else | 1280 | else |
1281 | { | 1281 | { |
1282 | i = ASN1_get_object(&p, &plen, &ptag, &pclass, len); | 1282 | i = ASN1_get_object(&p, &plen, &ptag, &pclass, len); |
1283 | if (ctx) | 1283 | if (ctx) |
1284 | { | 1284 | { |
1285 | ctx->ret = i; | 1285 | ctx->ret = i; |
1286 | ctx->plen = plen; | 1286 | ctx->plen = plen; |
1287 | ctx->pclass = pclass; | 1287 | ctx->pclass = pclass; |
@@ -1292,25 +1292,25 @@ static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass, | |||
1292 | * header can't exceed total amount of data available. | 1292 | * header can't exceed total amount of data available. |
1293 | */ | 1293 | */ |
1294 | if (!(i & 0x81) && ((plen + ctx->hdrlen) > len)) | 1294 | if (!(i & 0x81) && ((plen + ctx->hdrlen) > len)) |
1295 | { | 1295 | { |
1296 | ASN1err(ASN1_F_ASN1_CHECK_TLEN, | 1296 | ASN1err(ASN1_F_ASN1_CHECK_TLEN, |
1297 | ASN1_R_TOO_LONG); | 1297 | ASN1_R_TOO_LONG); |
1298 | asn1_tlc_clear(ctx); | 1298 | asn1_tlc_clear(ctx); |
1299 | return 0; | 1299 | return 0; |
1300 | } | ||
1301 | } | 1300 | } |
1302 | } | 1301 | } |
1302 | } | ||
1303 | 1303 | ||
1304 | if (i & 0x80) | 1304 | if (i & 0x80) |
1305 | { | 1305 | { |
1306 | ASN1err(ASN1_F_ASN1_CHECK_TLEN, ASN1_R_BAD_OBJECT_HEADER); | 1306 | ASN1err(ASN1_F_ASN1_CHECK_TLEN, ASN1_R_BAD_OBJECT_HEADER); |
1307 | asn1_tlc_clear(ctx); | 1307 | asn1_tlc_clear(ctx); |
1308 | return 0; | 1308 | return 0; |
1309 | } | 1309 | } |
1310 | if (exptag >= 0) | 1310 | if (exptag >= 0) |
1311 | { | 1311 | { |
1312 | if ((exptag != ptag) || (expclass != pclass)) | 1312 | if ((exptag != ptag) || (expclass != pclass)) |
1313 | { | 1313 | { |
1314 | /* If type is OPTIONAL, not an error: | 1314 | /* If type is OPTIONAL, not an error: |
1315 | * indicate missing type. | 1315 | * indicate missing type. |
1316 | */ | 1316 | */ |
@@ -1318,11 +1318,11 @@ static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass, | |||
1318 | asn1_tlc_clear(ctx); | 1318 | asn1_tlc_clear(ctx); |
1319 | ASN1err(ASN1_F_ASN1_CHECK_TLEN, ASN1_R_WRONG_TAG); | 1319 | ASN1err(ASN1_F_ASN1_CHECK_TLEN, ASN1_R_WRONG_TAG); |
1320 | return 0; | 1320 | return 0; |
1321 | } | 1321 | } |
1322 | /* We have a tag and class match: | 1322 | /* We have a tag and class match: |
1323 | * assume we are going to do something with it */ | 1323 | * assume we are going to do something with it */ |
1324 | asn1_tlc_clear(ctx); | 1324 | asn1_tlc_clear(ctx); |
1325 | } | 1325 | } |
1326 | 1326 | ||
1327 | if (i & 1) | 1327 | if (i & 1) |
1328 | plen = len - (p - q); | 1328 | plen = len - (p - q); |
@@ -1344,4 +1344,4 @@ static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass, | |||
1344 | 1344 | ||
1345 | *in = p; | 1345 | *in = p; |
1346 | return 1; | 1346 | return 1; |
1347 | } | 1347 | } |
diff --git a/src/lib/libcrypto/asn1/tasn_enc.c b/src/lib/libcrypto/asn1/tasn_enc.c index 54e3f7a94a..230164107d 100644 --- a/src/lib/libcrypto/asn1/tasn_enc.c +++ b/src/lib/libcrypto/asn1/tasn_enc.c | |||
@@ -82,14 +82,14 @@ static int asn1_item_flags_i2d(ASN1_VALUE *val, unsigned char **out, | |||
82 | 82 | ||
83 | int ASN1_item_ndef_i2d(ASN1_VALUE *val, unsigned char **out, | 83 | int ASN1_item_ndef_i2d(ASN1_VALUE *val, unsigned char **out, |
84 | const ASN1_ITEM *it) | 84 | const ASN1_ITEM *it) |
85 | { | 85 | { |
86 | return asn1_item_flags_i2d(val, out, it, ASN1_TFLG_NDEF); | 86 | return asn1_item_flags_i2d(val, out, it, ASN1_TFLG_NDEF); |
87 | } | 87 | } |
88 | 88 | ||
89 | int ASN1_item_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it) | 89 | int ASN1_item_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it) |
90 | { | 90 | { |
91 | return asn1_item_flags_i2d(val, out, it, 0); | 91 | return asn1_item_flags_i2d(val, out, it, 0); |
92 | } | 92 | } |
93 | 93 | ||
94 | /* Encode an ASN1 item, this is use by the | 94 | /* Encode an ASN1 item, this is use by the |
95 | * standard 'i2d' function. 'out' points to | 95 | * standard 'i2d' function. 'out' points to |
@@ -102,9 +102,9 @@ int ASN1_item_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it) | |||
102 | 102 | ||
103 | static int asn1_item_flags_i2d(ASN1_VALUE *val, unsigned char **out, | 103 | static int asn1_item_flags_i2d(ASN1_VALUE *val, unsigned char **out, |
104 | const ASN1_ITEM *it, int flags) | 104 | const ASN1_ITEM *it, int flags) |
105 | { | 105 | { |
106 | if (out && !*out) | 106 | if (out && !*out) |
107 | { | 107 | { |
108 | unsigned char *p, *buf; | 108 | unsigned char *p, *buf; |
109 | int len; | 109 | int len; |
110 | len = ASN1_item_ex_i2d(&val, NULL, it, -1, flags); | 110 | len = ASN1_item_ex_i2d(&val, NULL, it, -1, flags); |
@@ -117,10 +117,10 @@ static int asn1_item_flags_i2d(ASN1_VALUE *val, unsigned char **out, | |||
117 | ASN1_item_ex_i2d(&val, &p, it, -1, flags); | 117 | ASN1_item_ex_i2d(&val, &p, it, -1, flags); |
118 | *out = buf; | 118 | *out = buf; |
119 | return len; | 119 | return len; |
120 | } | 120 | } |
121 | 121 | ||
122 | return ASN1_item_ex_i2d(&val, out, it, -1, flags); | 122 | return ASN1_item_ex_i2d(&val, out, it, -1, flags); |
123 | } | 123 | } |
124 | 124 | ||
125 | /* Encode an item, taking care of IMPLICIT tagging (if any). | 125 | /* Encode an item, taking care of IMPLICIT tagging (if any). |
126 | * This function performs the normal item handling: it can be | 126 | * This function performs the normal item handling: it can be |
@@ -129,7 +129,7 @@ static int asn1_item_flags_i2d(ASN1_VALUE *val, unsigned char **out, | |||
129 | 129 | ||
130 | int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, | 130 | int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, |
131 | const ASN1_ITEM *it, int tag, int aclass) | 131 | const ASN1_ITEM *it, int tag, int aclass) |
132 | { | 132 | { |
133 | const ASN1_TEMPLATE *tt = NULL; | 133 | const ASN1_TEMPLATE *tt = NULL; |
134 | unsigned char *p = NULL; | 134 | unsigned char *p = NULL; |
135 | int i, seqcontlen, seqlen, ndef = 1; | 135 | int i, seqcontlen, seqlen, ndef = 1; |
@@ -145,7 +145,7 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, | |||
145 | asn1_cb = aux->asn1_cb; | 145 | asn1_cb = aux->asn1_cb; |
146 | 146 | ||
147 | switch(it->itype) | 147 | switch(it->itype) |
148 | { | 148 | { |
149 | 149 | ||
150 | case ASN1_ITYPE_PRIMITIVE: | 150 | case ASN1_ITYPE_PRIMITIVE: |
151 | if (it->templates) | 151 | if (it->templates) |
@@ -162,14 +162,14 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, | |||
162 | return 0; | 162 | return 0; |
163 | i = asn1_get_choice_selector(pval, it); | 163 | i = asn1_get_choice_selector(pval, it); |
164 | if ((i >= 0) && (i < it->tcount)) | 164 | if ((i >= 0) && (i < it->tcount)) |
165 | { | 165 | { |
166 | ASN1_VALUE **pchval; | 166 | ASN1_VALUE **pchval; |
167 | const ASN1_TEMPLATE *chtt; | 167 | const ASN1_TEMPLATE *chtt; |
168 | chtt = it->templates + i; | 168 | chtt = it->templates + i; |
169 | pchval = asn1_get_field_ptr(pval, chtt); | 169 | pchval = asn1_get_field_ptr(pval, chtt); |
170 | return asn1_template_ex_i2d(pchval, out, chtt, | 170 | return asn1_template_ex_i2d(pchval, out, chtt, |
171 | -1, aclass); | 171 | -1, aclass); |
172 | } | 172 | } |
173 | /* Fixme: error condition if selector out of range */ | 173 | /* Fixme: error condition if selector out of range */ |
174 | if (asn1_cb && !asn1_cb(ASN1_OP_I2D_POST, pval, it, NULL)) | 174 | if (asn1_cb && !asn1_cb(ASN1_OP_I2D_POST, pval, it, NULL)) |
175 | return 0; | 175 | return 0; |
@@ -210,17 +210,17 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, | |||
210 | seqcontlen = 0; | 210 | seqcontlen = 0; |
211 | /* If no IMPLICIT tagging set to SEQUENCE, UNIVERSAL */ | 211 | /* If no IMPLICIT tagging set to SEQUENCE, UNIVERSAL */ |
212 | if (tag == -1) | 212 | if (tag == -1) |
213 | { | 213 | { |
214 | tag = V_ASN1_SEQUENCE; | 214 | tag = V_ASN1_SEQUENCE; |
215 | /* Retain any other flags in aclass */ | 215 | /* Retain any other flags in aclass */ |
216 | aclass = (aclass & ~ASN1_TFLG_TAG_CLASS) | 216 | aclass = (aclass & ~ASN1_TFLG_TAG_CLASS) |
217 | | V_ASN1_UNIVERSAL; | 217 | | V_ASN1_UNIVERSAL; |
218 | } | 218 | } |
219 | if (asn1_cb && !asn1_cb(ASN1_OP_I2D_PRE, pval, it, NULL)) | 219 | if (asn1_cb && !asn1_cb(ASN1_OP_I2D_PRE, pval, it, NULL)) |
220 | return 0; | 220 | return 0; |
221 | /* First work out sequence content length */ | 221 | /* First work out sequence content length */ |
222 | for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) | 222 | for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) |
223 | { | 223 | { |
224 | const ASN1_TEMPLATE *seqtt; | 224 | const ASN1_TEMPLATE *seqtt; |
225 | ASN1_VALUE **pseqval; | 225 | ASN1_VALUE **pseqval; |
226 | seqtt = asn1_do_adb(pval, tt, 1); | 226 | seqtt = asn1_do_adb(pval, tt, 1); |
@@ -230,7 +230,7 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, | |||
230 | /* FIXME: check for errors in enhanced version */ | 230 | /* FIXME: check for errors in enhanced version */ |
231 | seqcontlen += asn1_template_ex_i2d(pseqval, NULL, seqtt, | 231 | seqcontlen += asn1_template_ex_i2d(pseqval, NULL, seqtt, |
232 | -1, aclass); | 232 | -1, aclass); |
233 | } | 233 | } |
234 | 234 | ||
235 | seqlen = ASN1_object_size(ndef, seqcontlen, tag); | 235 | seqlen = ASN1_object_size(ndef, seqcontlen, tag); |
236 | if (!out) | 236 | if (!out) |
@@ -238,7 +238,7 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, | |||
238 | /* Output SEQUENCE header */ | 238 | /* Output SEQUENCE header */ |
239 | ASN1_put_object(out, ndef, seqcontlen, tag, aclass); | 239 | ASN1_put_object(out, ndef, seqcontlen, tag, aclass); |
240 | for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) | 240 | for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) |
241 | { | 241 | { |
242 | const ASN1_TEMPLATE *seqtt; | 242 | const ASN1_TEMPLATE *seqtt; |
243 | ASN1_VALUE **pseqval; | 243 | ASN1_VALUE **pseqval; |
244 | seqtt = asn1_do_adb(pval, tt, 1); | 244 | seqtt = asn1_do_adb(pval, tt, 1); |
@@ -247,7 +247,7 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, | |||
247 | pseqval = asn1_get_field_ptr(pval, seqtt); | 247 | pseqval = asn1_get_field_ptr(pval, seqtt); |
248 | /* FIXME: check for errors in enhanced version */ | 248 | /* FIXME: check for errors in enhanced version */ |
249 | asn1_template_ex_i2d(pseqval, out, seqtt, -1, aclass); | 249 | asn1_template_ex_i2d(pseqval, out, seqtt, -1, aclass); |
250 | } | 250 | } |
251 | if (ndef == 2) | 251 | if (ndef == 2) |
252 | ASN1_put_eoc(out); | 252 | ASN1_put_eoc(out); |
253 | if (asn1_cb && !asn1_cb(ASN1_OP_I2D_POST, pval, it, NULL)) | 253 | if (asn1_cb && !asn1_cb(ASN1_OP_I2D_POST, pval, it, NULL)) |
@@ -257,19 +257,19 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, | |||
257 | default: | 257 | default: |
258 | return 0; | 258 | return 0; |
259 | 259 | ||
260 | } | ||
261 | return 0; | ||
262 | } | 260 | } |
261 | return 0; | ||
262 | } | ||
263 | 263 | ||
264 | int ASN1_template_i2d(ASN1_VALUE **pval, unsigned char **out, | 264 | int ASN1_template_i2d(ASN1_VALUE **pval, unsigned char **out, |
265 | const ASN1_TEMPLATE *tt) | 265 | const ASN1_TEMPLATE *tt) |
266 | { | 266 | { |
267 | return asn1_template_ex_i2d(pval, out, tt, -1, 0); | 267 | return asn1_template_ex_i2d(pval, out, tt, -1, 0); |
268 | } | 268 | } |
269 | 269 | ||
270 | static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out, | 270 | static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out, |
271 | const ASN1_TEMPLATE *tt, int tag, int iclass) | 271 | const ASN1_TEMPLATE *tt, int tag, int iclass) |
272 | { | 272 | { |
273 | int i, ret, flags, ttag, tclass, ndef; | 273 | int i, ret, flags, ttag, tclass, ndef; |
274 | flags = tt->flags; | 274 | flags = tt->flags; |
275 | /* Work out tag and class to use: tagging may come | 275 | /* Work out tag and class to use: tagging may come |
@@ -279,7 +279,7 @@ static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out, | |||
279 | * which should be noted and passed down to other levels. | 279 | * which should be noted and passed down to other levels. |
280 | */ | 280 | */ |
281 | if (flags & ASN1_TFLG_TAG_MASK) | 281 | if (flags & ASN1_TFLG_TAG_MASK) |
282 | { | 282 | { |
283 | /* Error if argument and template tagging */ | 283 | /* Error if argument and template tagging */ |
284 | if (tag != -1) | 284 | if (tag != -1) |
285 | /* FIXME: error code here */ | 285 | /* FIXME: error code here */ |
@@ -287,18 +287,18 @@ static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out, | |||
287 | /* Get tagging from template */ | 287 | /* Get tagging from template */ |
288 | ttag = tt->tag; | 288 | ttag = tt->tag; |
289 | tclass = flags & ASN1_TFLG_TAG_CLASS; | 289 | tclass = flags & ASN1_TFLG_TAG_CLASS; |
290 | } | 290 | } |
291 | else if (tag != -1) | 291 | else if (tag != -1) |
292 | { | 292 | { |
293 | /* No template tagging, get from arguments */ | 293 | /* No template tagging, get from arguments */ |
294 | ttag = tag; | 294 | ttag = tag; |
295 | tclass = iclass & ASN1_TFLG_TAG_CLASS; | 295 | tclass = iclass & ASN1_TFLG_TAG_CLASS; |
296 | } | 296 | } |
297 | else | 297 | else |
298 | { | 298 | { |
299 | ttag = -1; | 299 | ttag = -1; |
300 | tclass = 0; | 300 | tclass = 0; |
301 | } | 301 | } |
302 | /* | 302 | /* |
303 | * Remove any class mask from iflag. | 303 | * Remove any class mask from iflag. |
304 | */ | 304 | */ |
@@ -315,7 +315,7 @@ static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out, | |||
315 | else ndef = 1; | 315 | else ndef = 1; |
316 | 316 | ||
317 | if (flags & ASN1_TFLG_SK_MASK) | 317 | if (flags & ASN1_TFLG_SK_MASK) |
318 | { | 318 | { |
319 | /* SET OF, SEQUENCE OF */ | 319 | /* SET OF, SEQUENCE OF */ |
320 | STACK_OF(ASN1_VALUE) *sk = (STACK_OF(ASN1_VALUE) *)*pval; | 320 | STACK_OF(ASN1_VALUE) *sk = (STACK_OF(ASN1_VALUE) *)*pval; |
321 | int isset, sktag, skaclass; | 321 | int isset, sktag, skaclass; |
@@ -326,39 +326,39 @@ static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out, | |||
326 | return 0; | 326 | return 0; |
327 | 327 | ||
328 | if (flags & ASN1_TFLG_SET_OF) | 328 | if (flags & ASN1_TFLG_SET_OF) |
329 | { | 329 | { |
330 | isset = 1; | 330 | isset = 1; |
331 | /* 2 means we reorder */ | 331 | /* 2 means we reorder */ |
332 | if (flags & ASN1_TFLG_SEQUENCE_OF) | 332 | if (flags & ASN1_TFLG_SEQUENCE_OF) |
333 | isset = 2; | 333 | isset = 2; |
334 | } | 334 | } |
335 | else isset = 0; | 335 | else isset = 0; |
336 | 336 | ||
337 | /* Work out inner tag value: if EXPLICIT | 337 | /* Work out inner tag value: if EXPLICIT |
338 | * or no tagging use underlying type. | 338 | * or no tagging use underlying type. |
339 | */ | 339 | */ |
340 | if ((ttag != -1) && !(flags & ASN1_TFLG_EXPTAG)) | 340 | if ((ttag != -1) && !(flags & ASN1_TFLG_EXPTAG)) |
341 | { | 341 | { |
342 | sktag = ttag; | 342 | sktag = ttag; |
343 | skaclass = tclass; | 343 | skaclass = tclass; |
344 | } | 344 | } |
345 | else | 345 | else |
346 | { | 346 | { |
347 | skaclass = V_ASN1_UNIVERSAL; | 347 | skaclass = V_ASN1_UNIVERSAL; |
348 | if (isset) | 348 | if (isset) |
349 | sktag = V_ASN1_SET; | 349 | sktag = V_ASN1_SET; |
350 | else sktag = V_ASN1_SEQUENCE; | 350 | else sktag = V_ASN1_SEQUENCE; |
351 | } | 351 | } |
352 | 352 | ||
353 | /* Determine total length of items */ | 353 | /* Determine total length of items */ |
354 | skcontlen = 0; | 354 | skcontlen = 0; |
355 | for (i = 0; i < sk_ASN1_VALUE_num(sk); i++) | 355 | for (i = 0; i < sk_ASN1_VALUE_num(sk); i++) |
356 | { | 356 | { |
357 | skitem = sk_ASN1_VALUE_value(sk, i); | 357 | skitem = sk_ASN1_VALUE_value(sk, i); |
358 | skcontlen += ASN1_item_ex_i2d(&skitem, NULL, | 358 | skcontlen += ASN1_item_ex_i2d(&skitem, NULL, |
359 | ASN1_ITEM_ptr(tt->item), | 359 | ASN1_ITEM_ptr(tt->item), |
360 | -1, iclass); | 360 | -1, iclass); |
361 | } | 361 | } |
362 | sklen = ASN1_object_size(ndef, skcontlen, sktag); | 362 | sklen = ASN1_object_size(ndef, skcontlen, sktag); |
363 | /* If EXPLICIT need length of surrounding tag */ | 363 | /* If EXPLICIT need length of surrounding tag */ |
364 | if (flags & ASN1_TFLG_EXPTAG) | 364 | if (flags & ASN1_TFLG_EXPTAG) |
@@ -378,17 +378,17 @@ static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out, | |||
378 | asn1_set_seq_out(sk, out, skcontlen, ASN1_ITEM_ptr(tt->item), | 378 | asn1_set_seq_out(sk, out, skcontlen, ASN1_ITEM_ptr(tt->item), |
379 | isset, iclass); | 379 | isset, iclass); |
380 | if (ndef == 2) | 380 | if (ndef == 2) |
381 | { | 381 | { |
382 | ASN1_put_eoc(out); | 382 | ASN1_put_eoc(out); |
383 | if (flags & ASN1_TFLG_EXPTAG) | 383 | if (flags & ASN1_TFLG_EXPTAG) |
384 | ASN1_put_eoc(out); | 384 | ASN1_put_eoc(out); |
385 | } | 385 | } |
386 | 386 | ||
387 | return ret; | 387 | return ret; |
388 | } | 388 | } |
389 | 389 | ||
390 | if (flags & ASN1_TFLG_EXPTAG) | 390 | if (flags & ASN1_TFLG_EXPTAG) |
391 | { | 391 | { |
392 | /* EXPLICIT tagging */ | 392 | /* EXPLICIT tagging */ |
393 | /* Find length of tagged item */ | 393 | /* Find length of tagged item */ |
394 | i = ASN1_item_ex_i2d(pval, NULL, ASN1_ITEM_ptr(tt->item), | 394 | i = ASN1_item_ex_i2d(pval, NULL, ASN1_ITEM_ptr(tt->item), |
@@ -398,16 +398,16 @@ static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out, | |||
398 | /* Find length of EXPLICIT tag */ | 398 | /* Find length of EXPLICIT tag */ |
399 | ret = ASN1_object_size(ndef, i, ttag); | 399 | ret = ASN1_object_size(ndef, i, ttag); |
400 | if (out) | 400 | if (out) |
401 | { | 401 | { |
402 | /* Output tag and item */ | 402 | /* Output tag and item */ |
403 | ASN1_put_object(out, ndef, i, ttag, tclass); | 403 | ASN1_put_object(out, ndef, i, ttag, tclass); |
404 | ASN1_item_ex_i2d(pval, out, ASN1_ITEM_ptr(tt->item), | 404 | ASN1_item_ex_i2d(pval, out, ASN1_ITEM_ptr(tt->item), |
405 | -1, iclass); | 405 | -1, iclass); |
406 | if (ndef == 2) | 406 | if (ndef == 2) |
407 | ASN1_put_eoc(out); | 407 | ASN1_put_eoc(out); |
408 | } | ||
409 | return ret; | ||
410 | } | 408 | } |
409 | return ret; | ||
410 | } | ||
411 | 411 | ||
412 | /* Either normal or IMPLICIT tagging: combine class and flags */ | 412 | /* Either normal or IMPLICIT tagging: combine class and flags */ |
413 | return ASN1_item_ex_i2d(pval, out, ASN1_ITEM_ptr(tt->item), | 413 | return ASN1_item_ex_i2d(pval, out, ASN1_ITEM_ptr(tt->item), |
@@ -424,7 +424,7 @@ typedef struct { | |||
424 | } DER_ENC; | 424 | } DER_ENC; |
425 | 425 | ||
426 | static int der_cmp(const void *a, const void *b) | 426 | static int der_cmp(const void *a, const void *b) |
427 | { | 427 | { |
428 | const DER_ENC *d1 = a, *d2 = b; | 428 | const DER_ENC *d1 = a, *d2 = b; |
429 | int cmplen, i; | 429 | int cmplen, i; |
430 | cmplen = (d1->length < d2->length) ? d1->length : d2->length; | 430 | cmplen = (d1->length < d2->length) ? d1->length : d2->length; |
@@ -432,14 +432,14 @@ static int der_cmp(const void *a, const void *b) | |||
432 | if (i) | 432 | if (i) |
433 | return i; | 433 | return i; |
434 | return d1->length - d2->length; | 434 | return d1->length - d2->length; |
435 | } | 435 | } |
436 | 436 | ||
437 | /* Output the content octets of SET OF or SEQUENCE OF */ | 437 | /* Output the content octets of SET OF or SEQUENCE OF */ |
438 | 438 | ||
439 | static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out, | 439 | static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out, |
440 | int skcontlen, const ASN1_ITEM *item, | 440 | int skcontlen, const ASN1_ITEM *item, |
441 | int do_sort, int iclass) | 441 | int do_sort, int iclass) |
442 | { | 442 | { |
443 | int i; | 443 | int i; |
444 | ASN1_VALUE *skitem; | 444 | ASN1_VALUE *skitem; |
445 | unsigned char *tmpdat = NULL, *p = NULL; | 445 | unsigned char *tmpdat = NULL, *p = NULL; |
@@ -450,7 +450,7 @@ static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out, | |||
450 | if (sk_ASN1_VALUE_num(sk) < 2) | 450 | if (sk_ASN1_VALUE_num(sk) < 2) |
451 | do_sort = 0; | 451 | do_sort = 0; |
452 | else | 452 | else |
453 | { | 453 | { |
454 | derlst = malloc(sk_ASN1_VALUE_num(sk) | 454 | derlst = malloc(sk_ASN1_VALUE_num(sk) |
455 | * sizeof(*derlst)); | 455 | * sizeof(*derlst)); |
456 | tmpdat = malloc(skcontlen); | 456 | tmpdat = malloc(skcontlen); |
@@ -458,54 +458,54 @@ static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out, | |||
458 | free(derlst); | 458 | free(derlst); |
459 | free(tmpdat); | 459 | free(tmpdat); |
460 | return 0; | 460 | return 0; |
461 | } | ||
462 | } | 461 | } |
462 | } | ||
463 | /* If not sorting just output each item */ | 463 | /* If not sorting just output each item */ |
464 | if (!do_sort) | 464 | if (!do_sort) |
465 | { | 465 | { |
466 | for (i = 0; i < sk_ASN1_VALUE_num(sk); i++) | 466 | for (i = 0; i < sk_ASN1_VALUE_num(sk); i++) |
467 | { | 467 | { |
468 | skitem = sk_ASN1_VALUE_value(sk, i); | 468 | skitem = sk_ASN1_VALUE_value(sk, i); |
469 | ASN1_item_ex_i2d(&skitem, out, item, -1, iclass); | 469 | ASN1_item_ex_i2d(&skitem, out, item, -1, iclass); |
470 | } | ||
471 | return 1; | ||
472 | } | 470 | } |
471 | return 1; | ||
472 | } | ||
473 | p = tmpdat; | 473 | p = tmpdat; |
474 | 474 | ||
475 | /* Doing sort: build up a list of each member's DER encoding */ | 475 | /* Doing sort: build up a list of each member's DER encoding */ |
476 | for (i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++) | 476 | for (i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++) |
477 | { | 477 | { |
478 | skitem = sk_ASN1_VALUE_value(sk, i); | 478 | skitem = sk_ASN1_VALUE_value(sk, i); |
479 | tder->data = p; | 479 | tder->data = p; |
480 | tder->length = ASN1_item_ex_i2d(&skitem, &p, item, -1, iclass); | 480 | tder->length = ASN1_item_ex_i2d(&skitem, &p, item, -1, iclass); |
481 | tder->field = skitem; | 481 | tder->field = skitem; |
482 | } | 482 | } |
483 | 483 | ||
484 | /* Now sort them */ | 484 | /* Now sort them */ |
485 | qsort(derlst, sk_ASN1_VALUE_num(sk), sizeof(*derlst), der_cmp); | 485 | qsort(derlst, sk_ASN1_VALUE_num(sk), sizeof(*derlst), der_cmp); |
486 | /* Output sorted DER encoding */ | 486 | /* Output sorted DER encoding */ |
487 | p = *out; | 487 | p = *out; |
488 | for (i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++) | 488 | for (i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++) |
489 | { | 489 | { |
490 | memcpy(p, tder->data, tder->length); | 490 | memcpy(p, tder->data, tder->length); |
491 | p += tder->length; | 491 | p += tder->length; |
492 | } | 492 | } |
493 | *out = p; | 493 | *out = p; |
494 | /* If do_sort is 2 then reorder the STACK */ | 494 | /* If do_sort is 2 then reorder the STACK */ |
495 | if (do_sort == 2) | 495 | if (do_sort == 2) |
496 | { | 496 | { |
497 | for (i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); | 497 | for (i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); |
498 | i++, tder++) | 498 | i++, tder++) |
499 | (void)sk_ASN1_VALUE_set(sk, i, tder->field); | 499 | (void)sk_ASN1_VALUE_set(sk, i, tder->field); |
500 | } | 500 | } |
501 | free(derlst); | 501 | free(derlst); |
502 | free(tmpdat); | 502 | free(tmpdat); |
503 | return 1; | 503 | return 1; |
504 | } | 504 | } |
505 | 505 | ||
506 | static int asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out, | 506 | static int asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out, |
507 | const ASN1_ITEM *it, int tag, int aclass) | 507 | const ASN1_ITEM *it, int tag, int aclass) |
508 | { | 508 | { |
509 | int len; | 509 | int len; |
510 | int utype; | 510 | int utype; |
511 | int usetag; | 511 | int usetag; |
@@ -537,17 +537,17 @@ static int asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out, | |||
537 | 537 | ||
538 | /* -2 return is special meaning use ndef */ | 538 | /* -2 return is special meaning use ndef */ |
539 | if (len == -2) | 539 | if (len == -2) |
540 | { | 540 | { |
541 | ndef = 2; | 541 | ndef = 2; |
542 | len = 0; | 542 | len = 0; |
543 | } | 543 | } |
544 | 544 | ||
545 | /* If not implicitly tagged get tag from underlying type */ | 545 | /* If not implicitly tagged get tag from underlying type */ |
546 | if (tag == -1) tag = utype; | 546 | if (tag == -1) tag = utype; |
547 | 547 | ||
548 | /* Output tag+length followed by content octets */ | 548 | /* Output tag+length followed by content octets */ |
549 | if (out) | 549 | if (out) |
550 | { | 550 | { |
551 | if (usetag) | 551 | if (usetag) |
552 | ASN1_put_object(out, ndef, len, tag, aclass); | 552 | ASN1_put_object(out, ndef, len, tag, aclass); |
553 | asn1_ex_i2c(pval, *out, &utype, it); | 553 | asn1_ex_i2c(pval, *out, &utype, it); |
@@ -555,18 +555,18 @@ static int asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out, | |||
555 | ASN1_put_eoc(out); | 555 | ASN1_put_eoc(out); |
556 | else | 556 | else |
557 | *out += len; | 557 | *out += len; |
558 | } | 558 | } |
559 | 559 | ||
560 | if (usetag) | 560 | if (usetag) |
561 | return ASN1_object_size(ndef, len, tag); | 561 | return ASN1_object_size(ndef, len, tag); |
562 | return len; | 562 | return len; |
563 | } | 563 | } |
564 | 564 | ||
565 | /* Produce content octets from a structure */ | 565 | /* Produce content octets from a structure */ |
566 | 566 | ||
567 | int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype, | 567 | int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype, |
568 | const ASN1_ITEM *it) | 568 | const ASN1_ITEM *it) |
569 | { | 569 | { |
570 | ASN1_BOOLEAN *tbool = NULL; | 570 | ASN1_BOOLEAN *tbool = NULL; |
571 | ASN1_STRING *strtmp; | 571 | ASN1_STRING *strtmp; |
572 | ASN1_OBJECT *otmp; | 572 | ASN1_OBJECT *otmp; |
@@ -582,30 +582,30 @@ int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype, | |||
582 | /* Should type be omitted? */ | 582 | /* Should type be omitted? */ |
583 | if ((it->itype != ASN1_ITYPE_PRIMITIVE) | 583 | if ((it->itype != ASN1_ITYPE_PRIMITIVE) |
584 | || (it->utype != V_ASN1_BOOLEAN)) | 584 | || (it->utype != V_ASN1_BOOLEAN)) |
585 | { | 585 | { |
586 | if (!*pval) return -1; | 586 | if (!*pval) return -1; |
587 | } | 587 | } |
588 | 588 | ||
589 | if (it->itype == ASN1_ITYPE_MSTRING) | 589 | if (it->itype == ASN1_ITYPE_MSTRING) |
590 | { | 590 | { |
591 | /* If MSTRING type set the underlying type */ | 591 | /* If MSTRING type set the underlying type */ |
592 | strtmp = (ASN1_STRING *)*pval; | 592 | strtmp = (ASN1_STRING *)*pval; |
593 | utype = strtmp->type; | 593 | utype = strtmp->type; |
594 | *putype = utype; | 594 | *putype = utype; |
595 | } | 595 | } |
596 | else if (it->utype == V_ASN1_ANY) | 596 | else if (it->utype == V_ASN1_ANY) |
597 | { | 597 | { |
598 | /* If ANY set type and pointer to value */ | 598 | /* If ANY set type and pointer to value */ |
599 | ASN1_TYPE *typ; | 599 | ASN1_TYPE *typ; |
600 | typ = (ASN1_TYPE *)*pval; | 600 | typ = (ASN1_TYPE *)*pval; |
601 | utype = typ->type; | 601 | utype = typ->type; |
602 | *putype = utype; | 602 | *putype = utype; |
603 | pval = &typ->value.asn1_value; | 603 | pval = &typ->value.asn1_value; |
604 | } | 604 | } |
605 | else utype = *putype; | 605 | else utype = *putype; |
606 | 606 | ||
607 | switch(utype) | 607 | switch(utype) |
608 | { | 608 | { |
609 | case V_ASN1_OBJECT: | 609 | case V_ASN1_OBJECT: |
610 | otmp = (ASN1_OBJECT *)*pval; | 610 | otmp = (ASN1_OBJECT *)*pval; |
611 | cont = otmp->data; | 611 | cont = otmp->data; |
@@ -622,13 +622,13 @@ int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype, | |||
622 | if (*tbool == -1) | 622 | if (*tbool == -1) |
623 | return -1; | 623 | return -1; |
624 | if (it->utype != V_ASN1_ANY) | 624 | if (it->utype != V_ASN1_ANY) |
625 | { | 625 | { |
626 | /* Default handling if value == size field then omit */ | 626 | /* Default handling if value == size field then omit */ |
627 | if (*tbool && (it->size > 0)) | 627 | if (*tbool && (it->size > 0)) |
628 | return -1; | 628 | return -1; |
629 | if (!*tbool && !it->size) | 629 | if (!*tbool && !it->size) |
630 | return -1; | 630 | return -1; |
631 | } | 631 | } |
632 | c = (unsigned char)*tbool; | 632 | c = (unsigned char)*tbool; |
633 | cont = &c; | 633 | cont = &c; |
634 | len = 1; | 634 | len = 1; |
@@ -672,22 +672,22 @@ int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype, | |||
672 | /* Special handling for NDEF */ | 672 | /* Special handling for NDEF */ |
673 | if ((it->size == ASN1_TFLG_NDEF) | 673 | if ((it->size == ASN1_TFLG_NDEF) |
674 | && (strtmp->flags & ASN1_STRING_FLAG_NDEF)) | 674 | && (strtmp->flags & ASN1_STRING_FLAG_NDEF)) |
675 | { | 675 | { |
676 | if (cout) | 676 | if (cout) |
677 | { | 677 | { |
678 | strtmp->data = cout; | 678 | strtmp->data = cout; |
679 | strtmp->length = 0; | 679 | strtmp->length = 0; |
680 | } | 680 | } |
681 | /* Special return code */ | 681 | /* Special return code */ |
682 | return -2; | 682 | return -2; |
683 | } | 683 | } |
684 | cont = strtmp->data; | 684 | cont = strtmp->data; |
685 | len = strtmp->length; | 685 | len = strtmp->length; |
686 | 686 | ||
687 | break; | 687 | break; |
688 | 688 | ||
689 | } | 689 | } |
690 | if (cout && len) | 690 | if (cout && len) |
691 | memcpy(cout, cont, len); | 691 | memcpy(cout, cont, len); |
692 | return len; | 692 | return len; |
693 | } | 693 | } |
diff --git a/src/lib/libcrypto/asn1/tasn_fre.c b/src/lib/libcrypto/asn1/tasn_fre.c index b04034ba4c..b321de6615 100644 --- a/src/lib/libcrypto/asn1/tasn_fre.c +++ b/src/lib/libcrypto/asn1/tasn_fre.c | |||
@@ -67,17 +67,17 @@ static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int c | |||
67 | /* Free up an ASN1 structure */ | 67 | /* Free up an ASN1 structure */ |
68 | 68 | ||
69 | void ASN1_item_free(ASN1_VALUE *val, const ASN1_ITEM *it) | 69 | void ASN1_item_free(ASN1_VALUE *val, const ASN1_ITEM *it) |
70 | { | 70 | { |
71 | asn1_item_combine_free(&val, it, 0); | 71 | asn1_item_combine_free(&val, it, 0); |
72 | } | 72 | } |
73 | 73 | ||
74 | void ASN1_item_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it) | 74 | void ASN1_item_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it) |
75 | { | 75 | { |
76 | asn1_item_combine_free(pval, it, 0); | 76 | asn1_item_combine_free(pval, it, 0); |
77 | } | 77 | } |
78 | 78 | ||
79 | static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine) | 79 | static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine) |
80 | { | 80 | { |
81 | const ASN1_TEMPLATE *tt = NULL, *seqtt; | 81 | const ASN1_TEMPLATE *tt = NULL, *seqtt; |
82 | const ASN1_EXTERN_FUNCS *ef; | 82 | const ASN1_EXTERN_FUNCS *ef; |
83 | const ASN1_COMPAT_FUNCS *cf; | 83 | const ASN1_COMPAT_FUNCS *cf; |
@@ -94,7 +94,7 @@ static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int c | |||
94 | asn1_cb = 0; | 94 | asn1_cb = 0; |
95 | 95 | ||
96 | switch(it->itype) | 96 | switch(it->itype) |
97 | { | 97 | { |
98 | 98 | ||
99 | case ASN1_ITYPE_PRIMITIVE: | 99 | case ASN1_ITYPE_PRIMITIVE: |
100 | if (it->templates) | 100 | if (it->templates) |
@@ -109,26 +109,26 @@ static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int c | |||
109 | 109 | ||
110 | case ASN1_ITYPE_CHOICE: | 110 | case ASN1_ITYPE_CHOICE: |
111 | if (asn1_cb) | 111 | if (asn1_cb) |
112 | { | 112 | { |
113 | i = asn1_cb(ASN1_OP_FREE_PRE, pval, it, NULL); | 113 | i = asn1_cb(ASN1_OP_FREE_PRE, pval, it, NULL); |
114 | if (i == 2) | 114 | if (i == 2) |
115 | return; | 115 | return; |
116 | } | 116 | } |
117 | i = asn1_get_choice_selector(pval, it); | 117 | i = asn1_get_choice_selector(pval, it); |
118 | if ((i >= 0) && (i < it->tcount)) | 118 | if ((i >= 0) && (i < it->tcount)) |
119 | { | 119 | { |
120 | ASN1_VALUE **pchval; | 120 | ASN1_VALUE **pchval; |
121 | tt = it->templates + i; | 121 | tt = it->templates + i; |
122 | pchval = asn1_get_field_ptr(pval, tt); | 122 | pchval = asn1_get_field_ptr(pval, tt); |
123 | ASN1_template_free(pchval, tt); | 123 | ASN1_template_free(pchval, tt); |
124 | } | 124 | } |
125 | if (asn1_cb) | 125 | if (asn1_cb) |
126 | asn1_cb(ASN1_OP_FREE_POST, pval, it, NULL); | 126 | asn1_cb(ASN1_OP_FREE_POST, pval, it, NULL); |
127 | if (!combine) | 127 | if (!combine) |
128 | { | 128 | { |
129 | free(*pval); | 129 | free(*pval); |
130 | *pval = NULL; | 130 | *pval = NULL; |
131 | } | 131 | } |
132 | break; | 132 | break; |
133 | 133 | ||
134 | case ASN1_ITYPE_COMPAT: | 134 | case ASN1_ITYPE_COMPAT: |
@@ -148,11 +148,11 @@ static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int c | |||
148 | if (asn1_do_lock(pval, -1, it) > 0) | 148 | if (asn1_do_lock(pval, -1, it) > 0) |
149 | return; | 149 | return; |
150 | if (asn1_cb) | 150 | if (asn1_cb) |
151 | { | 151 | { |
152 | i = asn1_cb(ASN1_OP_FREE_PRE, pval, it, NULL); | 152 | i = asn1_cb(ASN1_OP_FREE_PRE, pval, it, NULL); |
153 | if (i == 2) | 153 | if (i == 2) |
154 | return; | 154 | return; |
155 | } | 155 | } |
156 | asn1_enc_free(pval, it); | 156 | asn1_enc_free(pval, it); |
157 | /* If we free up as normal we will invalidate any | 157 | /* If we free up as normal we will invalidate any |
158 | * ANY DEFINED BY field and we wont be able to | 158 | * ANY DEFINED BY field and we wont be able to |
@@ -161,83 +161,83 @@ static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int c | |||
161 | */ | 161 | */ |
162 | tt = it->templates + it->tcount - 1; | 162 | tt = it->templates + it->tcount - 1; |
163 | for (i = 0; i < it->tcount; tt--, i++) | 163 | for (i = 0; i < it->tcount; tt--, i++) |
164 | { | 164 | { |
165 | ASN1_VALUE **pseqval; | 165 | ASN1_VALUE **pseqval; |
166 | seqtt = asn1_do_adb(pval, tt, 0); | 166 | seqtt = asn1_do_adb(pval, tt, 0); |
167 | if (!seqtt) | 167 | if (!seqtt) |
168 | continue; | 168 | continue; |
169 | pseqval = asn1_get_field_ptr(pval, seqtt); | 169 | pseqval = asn1_get_field_ptr(pval, seqtt); |
170 | ASN1_template_free(pseqval, seqtt); | 170 | ASN1_template_free(pseqval, seqtt); |
171 | } | 171 | } |
172 | if (asn1_cb) | 172 | if (asn1_cb) |
173 | asn1_cb(ASN1_OP_FREE_POST, pval, it, NULL); | 173 | asn1_cb(ASN1_OP_FREE_POST, pval, it, NULL); |
174 | if (!combine) | 174 | if (!combine) |
175 | { | 175 | { |
176 | free(*pval); | 176 | free(*pval); |
177 | *pval = NULL; | 177 | *pval = NULL; |
178 | } | ||
179 | break; | ||
180 | } | 178 | } |
179 | break; | ||
181 | } | 180 | } |
181 | } | ||
182 | 182 | ||
183 | void ASN1_template_free(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) | 183 | void ASN1_template_free(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) |
184 | { | 184 | { |
185 | int i; | 185 | int i; |
186 | if (tt->flags & ASN1_TFLG_SK_MASK) | 186 | if (tt->flags & ASN1_TFLG_SK_MASK) |
187 | { | 187 | { |
188 | STACK_OF(ASN1_VALUE) *sk = (STACK_OF(ASN1_VALUE) *)*pval; | 188 | STACK_OF(ASN1_VALUE) *sk = (STACK_OF(ASN1_VALUE) *)*pval; |
189 | for (i = 0; i < sk_ASN1_VALUE_num(sk); i++) | 189 | for (i = 0; i < sk_ASN1_VALUE_num(sk); i++) |
190 | { | 190 | { |
191 | ASN1_VALUE *vtmp; | 191 | ASN1_VALUE *vtmp; |
192 | vtmp = sk_ASN1_VALUE_value(sk, i); | 192 | vtmp = sk_ASN1_VALUE_value(sk, i); |
193 | asn1_item_combine_free(&vtmp, ASN1_ITEM_ptr(tt->item), | 193 | asn1_item_combine_free(&vtmp, ASN1_ITEM_ptr(tt->item), |
194 | 0); | 194 | 0); |
195 | } | 195 | } |
196 | sk_ASN1_VALUE_free(sk); | 196 | sk_ASN1_VALUE_free(sk); |
197 | *pval = NULL; | 197 | *pval = NULL; |
198 | } | 198 | } |
199 | else | 199 | else |
200 | asn1_item_combine_free(pval, ASN1_ITEM_ptr(tt->item), | 200 | asn1_item_combine_free(pval, ASN1_ITEM_ptr(tt->item), |
201 | tt->flags & ASN1_TFLG_COMBINE); | 201 | tt->flags & ASN1_TFLG_COMBINE); |
202 | } | 202 | } |
203 | 203 | ||
204 | void ASN1_primitive_free(ASN1_VALUE **pval, const ASN1_ITEM *it) | 204 | void ASN1_primitive_free(ASN1_VALUE **pval, const ASN1_ITEM *it) |
205 | { | 205 | { |
206 | int utype; | 206 | int utype; |
207 | if (it) | 207 | if (it) |
208 | { | 208 | { |
209 | const ASN1_PRIMITIVE_FUNCS *pf; | 209 | const ASN1_PRIMITIVE_FUNCS *pf; |
210 | pf = it->funcs; | 210 | pf = it->funcs; |
211 | if (pf && pf->prim_free) | 211 | if (pf && pf->prim_free) |
212 | { | 212 | { |
213 | pf->prim_free(pval, it); | 213 | pf->prim_free(pval, it); |
214 | return; | 214 | return; |
215 | } | ||
216 | } | 215 | } |
216 | } | ||
217 | /* Special case: if 'it' is NULL free contents of ASN1_TYPE */ | 217 | /* Special case: if 'it' is NULL free contents of ASN1_TYPE */ |
218 | if (!it) | 218 | if (!it) |
219 | { | 219 | { |
220 | ASN1_TYPE *typ = (ASN1_TYPE *)*pval; | 220 | ASN1_TYPE *typ = (ASN1_TYPE *)*pval; |
221 | utype = typ->type; | 221 | utype = typ->type; |
222 | pval = &typ->value.asn1_value; | 222 | pval = &typ->value.asn1_value; |
223 | if (!*pval) | 223 | if (!*pval) |
224 | return; | 224 | return; |
225 | } | 225 | } |
226 | else if (it->itype == ASN1_ITYPE_MSTRING) | 226 | else if (it->itype == ASN1_ITYPE_MSTRING) |
227 | { | 227 | { |
228 | utype = -1; | 228 | utype = -1; |
229 | if (!*pval) | 229 | if (!*pval) |
230 | return; | 230 | return; |
231 | } | 231 | } |
232 | else | 232 | else |
233 | { | 233 | { |
234 | utype = it->utype; | 234 | utype = it->utype; |
235 | if ((utype != V_ASN1_BOOLEAN) && !*pval) | 235 | if ((utype != V_ASN1_BOOLEAN) && !*pval) |
236 | return; | 236 | return; |
237 | } | 237 | } |
238 | 238 | ||
239 | switch(utype) | 239 | switch(utype) |
240 | { | 240 | { |
241 | case V_ASN1_OBJECT: | 241 | case V_ASN1_OBJECT: |
242 | ASN1_OBJECT_free((ASN1_OBJECT *)*pval); | 242 | ASN1_OBJECT_free((ASN1_OBJECT *)*pval); |
243 | break; | 243 | break; |
@@ -261,6 +261,6 @@ void ASN1_primitive_free(ASN1_VALUE **pval, const ASN1_ITEM *it) | |||
261 | ASN1_STRING_free((ASN1_STRING *)*pval); | 261 | ASN1_STRING_free((ASN1_STRING *)*pval); |
262 | *pval = NULL; | 262 | *pval = NULL; |
263 | break; | 263 | break; |
264 | } | ||
265 | *pval = NULL; | ||
266 | } | 264 | } |
265 | *pval = NULL; | ||
266 | } | ||
diff --git a/src/lib/libcrypto/asn1/tasn_new.c b/src/lib/libcrypto/asn1/tasn_new.c index aab9ef08c4..f5d7c690b8 100644 --- a/src/lib/libcrypto/asn1/tasn_new.c +++ b/src/lib/libcrypto/asn1/tasn_new.c | |||
@@ -71,23 +71,23 @@ static void asn1_template_clear(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt); | |||
71 | static void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it); | 71 | static void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it); |
72 | 72 | ||
73 | ASN1_VALUE *ASN1_item_new(const ASN1_ITEM *it) | 73 | ASN1_VALUE *ASN1_item_new(const ASN1_ITEM *it) |
74 | { | 74 | { |
75 | ASN1_VALUE *ret = NULL; | 75 | ASN1_VALUE *ret = NULL; |
76 | if (ASN1_item_ex_new(&ret, it) > 0) | 76 | if (ASN1_item_ex_new(&ret, it) > 0) |
77 | return ret; | 77 | return ret; |
78 | return NULL; | 78 | return NULL; |
79 | } | 79 | } |
80 | 80 | ||
81 | /* Allocate an ASN1 structure */ | 81 | /* Allocate an ASN1 structure */ |
82 | 82 | ||
83 | int ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it) | 83 | int ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it) |
84 | { | 84 | { |
85 | return asn1_item_ex_combine_new(pval, it, 0); | 85 | return asn1_item_ex_combine_new(pval, it, 0); |
86 | } | 86 | } |
87 | 87 | ||
88 | static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, | 88 | static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, |
89 | int combine) | 89 | int combine) |
90 | { | 90 | { |
91 | const ASN1_TEMPLATE *tt = NULL; | 91 | const ASN1_TEMPLATE *tt = NULL; |
92 | const ASN1_COMPAT_FUNCS *cf; | 92 | const ASN1_COMPAT_FUNCS *cf; |
93 | const ASN1_EXTERN_FUNCS *ef; | 93 | const ASN1_EXTERN_FUNCS *ef; |
@@ -108,15 +108,15 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, | |||
108 | #endif | 108 | #endif |
109 | 109 | ||
110 | switch(it->itype) | 110 | switch(it->itype) |
111 | { | 111 | { |
112 | 112 | ||
113 | case ASN1_ITYPE_EXTERN: | 113 | case ASN1_ITYPE_EXTERN: |
114 | ef = it->funcs; | 114 | ef = it->funcs; |
115 | if (ef && ef->asn1_ex_new) | 115 | if (ef && ef->asn1_ex_new) |
116 | { | 116 | { |
117 | if (!ef->asn1_ex_new(pval, it)) | 117 | if (!ef->asn1_ex_new(pval, it)) |
118 | goto memerr; | 118 | goto memerr; |
119 | } | 119 | } |
120 | break; | 120 | break; |
121 | 121 | ||
122 | case ASN1_ITYPE_COMPAT: | 122 | case ASN1_ITYPE_COMPAT: |
@@ -125,15 +125,15 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, | |||
125 | *pval = cf->asn1_new(); | 125 | *pval = cf->asn1_new(); |
126 | if (!*pval) | 126 | if (!*pval) |
127 | goto memerr; | 127 | goto memerr; |
128 | } | 128 | } |
129 | break; | 129 | break; |
130 | 130 | ||
131 | case ASN1_ITYPE_PRIMITIVE: | 131 | case ASN1_ITYPE_PRIMITIVE: |
132 | if (it->templates) | 132 | if (it->templates) |
133 | { | 133 | { |
134 | if (!ASN1_template_new(pval, it->templates)) | 134 | if (!ASN1_template_new(pval, it->templates)) |
135 | goto memerr; | 135 | goto memerr; |
136 | } | 136 | } |
137 | else if (!ASN1_primitive_new(pval, it)) | 137 | else if (!ASN1_primitive_new(pval, it)) |
138 | goto memerr; | 138 | goto memerr; |
139 | break; | 139 | break; |
@@ -145,26 +145,26 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, | |||
145 | 145 | ||
146 | case ASN1_ITYPE_CHOICE: | 146 | case ASN1_ITYPE_CHOICE: |
147 | if (asn1_cb) | 147 | if (asn1_cb) |
148 | { | 148 | { |
149 | i = asn1_cb(ASN1_OP_NEW_PRE, pval, it, NULL); | 149 | i = asn1_cb(ASN1_OP_NEW_PRE, pval, it, NULL); |
150 | if (!i) | 150 | if (!i) |
151 | goto auxerr; | 151 | goto auxerr; |
152 | if (i==2) | 152 | if (i==2) |
153 | { | 153 | { |
154 | #ifdef CRYPTO_MDEBUG | 154 | #ifdef CRYPTO_MDEBUG |
155 | if (it->sname) | 155 | if (it->sname) |
156 | CRYPTO_pop_info(); | 156 | CRYPTO_pop_info(); |
157 | #endif | 157 | #endif |
158 | return 1; | 158 | return 1; |
159 | } | ||
160 | } | 159 | } |
160 | } | ||
161 | if (!combine) | 161 | if (!combine) |
162 | { | 162 | { |
163 | *pval = malloc(it->size); | 163 | *pval = malloc(it->size); |
164 | if (!*pval) | 164 | if (!*pval) |
165 | goto memerr; | 165 | goto memerr; |
166 | memset(*pval, 0, it->size); | 166 | memset(*pval, 0, it->size); |
167 | } | 167 | } |
168 | asn1_set_choice_selector(pval, -1, it); | 168 | asn1_set_choice_selector(pval, -1, it); |
169 | if (asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it, NULL)) | 169 | if (asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it, NULL)) |
170 | goto auxerr; | 170 | goto auxerr; |
@@ -173,38 +173,38 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, | |||
173 | case ASN1_ITYPE_NDEF_SEQUENCE: | 173 | case ASN1_ITYPE_NDEF_SEQUENCE: |
174 | case ASN1_ITYPE_SEQUENCE: | 174 | case ASN1_ITYPE_SEQUENCE: |
175 | if (asn1_cb) | 175 | if (asn1_cb) |
176 | { | 176 | { |
177 | i = asn1_cb(ASN1_OP_NEW_PRE, pval, it, NULL); | 177 | i = asn1_cb(ASN1_OP_NEW_PRE, pval, it, NULL); |
178 | if (!i) | 178 | if (!i) |
179 | goto auxerr; | 179 | goto auxerr; |
180 | if (i==2) | 180 | if (i==2) |
181 | { | 181 | { |
182 | #ifdef CRYPTO_MDEBUG | 182 | #ifdef CRYPTO_MDEBUG |
183 | if (it->sname) | 183 | if (it->sname) |
184 | CRYPTO_pop_info(); | 184 | CRYPTO_pop_info(); |
185 | #endif | 185 | #endif |
186 | return 1; | 186 | return 1; |
187 | } | ||
188 | } | 187 | } |
188 | } | ||
189 | if (!combine) | 189 | if (!combine) |
190 | { | 190 | { |
191 | *pval = malloc(it->size); | 191 | *pval = malloc(it->size); |
192 | if (!*pval) | 192 | if (!*pval) |
193 | goto memerr; | 193 | goto memerr; |
194 | memset(*pval, 0, it->size); | 194 | memset(*pval, 0, it->size); |
195 | asn1_do_lock(pval, 0, it); | 195 | asn1_do_lock(pval, 0, it); |
196 | asn1_enc_init(pval, it); | 196 | asn1_enc_init(pval, it); |
197 | } | 197 | } |
198 | for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) | 198 | for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) |
199 | { | 199 | { |
200 | pseqval = asn1_get_field_ptr(pval, tt); | 200 | pseqval = asn1_get_field_ptr(pval, tt); |
201 | if (!ASN1_template_new(pseqval, tt)) | 201 | if (!ASN1_template_new(pseqval, tt)) |
202 | goto memerr; | 202 | goto memerr; |
203 | } | 203 | } |
204 | if (asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it, NULL)) | 204 | if (asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it, NULL)) |
205 | goto auxerr; | 205 | goto auxerr; |
206 | break; | 206 | break; |
207 | } | 207 | } |
208 | #ifdef CRYPTO_MDEBUG | 208 | #ifdef CRYPTO_MDEBUG |
209 | if (it->sname) CRYPTO_pop_info(); | 209 | if (it->sname) CRYPTO_pop_info(); |
210 | #endif | 210 | #endif |
@@ -225,14 +225,14 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, | |||
225 | #endif | 225 | #endif |
226 | return 0; | 226 | return 0; |
227 | 227 | ||
228 | } | 228 | } |
229 | 229 | ||
230 | static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it) | 230 | static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it) |
231 | { | 231 | { |
232 | const ASN1_EXTERN_FUNCS *ef; | 232 | const ASN1_EXTERN_FUNCS *ef; |
233 | 233 | ||
234 | switch(it->itype) | 234 | switch(it->itype) |
235 | { | 235 | { |
236 | 236 | ||
237 | case ASN1_ITYPE_EXTERN: | 237 | case ASN1_ITYPE_EXTERN: |
238 | ef = it->funcs; | 238 | ef = it->funcs; |
@@ -259,45 +259,45 @@ static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it) | |||
259 | case ASN1_ITYPE_NDEF_SEQUENCE: | 259 | case ASN1_ITYPE_NDEF_SEQUENCE: |
260 | *pval = NULL; | 260 | *pval = NULL; |
261 | break; | 261 | break; |
262 | } | ||
263 | } | 262 | } |
263 | } | ||
264 | 264 | ||
265 | 265 | ||
266 | int ASN1_template_new(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) | 266 | int ASN1_template_new(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) |
267 | { | 267 | { |
268 | const ASN1_ITEM *it = ASN1_ITEM_ptr(tt->item); | 268 | const ASN1_ITEM *it = ASN1_ITEM_ptr(tt->item); |
269 | int ret; | 269 | int ret; |
270 | if (tt->flags & ASN1_TFLG_OPTIONAL) | 270 | if (tt->flags & ASN1_TFLG_OPTIONAL) |
271 | { | 271 | { |
272 | asn1_template_clear(pval, tt); | 272 | asn1_template_clear(pval, tt); |
273 | return 1; | 273 | return 1; |
274 | } | 274 | } |
275 | /* If ANY DEFINED BY nothing to do */ | 275 | /* If ANY DEFINED BY nothing to do */ |
276 | 276 | ||
277 | if (tt->flags & ASN1_TFLG_ADB_MASK) | 277 | if (tt->flags & ASN1_TFLG_ADB_MASK) |
278 | { | 278 | { |
279 | *pval = NULL; | 279 | *pval = NULL; |
280 | return 1; | 280 | return 1; |
281 | } | 281 | } |
282 | #ifdef CRYPTO_MDEBUG | 282 | #ifdef CRYPTO_MDEBUG |
283 | if (tt->field_name) | 283 | if (tt->field_name) |
284 | CRYPTO_push_info(tt->field_name); | 284 | CRYPTO_push_info(tt->field_name); |
285 | #endif | 285 | #endif |
286 | /* If SET OF or SEQUENCE OF, its a STACK */ | 286 | /* If SET OF or SEQUENCE OF, its a STACK */ |
287 | if (tt->flags & ASN1_TFLG_SK_MASK) | 287 | if (tt->flags & ASN1_TFLG_SK_MASK) |
288 | { | 288 | { |
289 | STACK_OF(ASN1_VALUE) *skval; | 289 | STACK_OF(ASN1_VALUE) *skval; |
290 | skval = sk_ASN1_VALUE_new_null(); | 290 | skval = sk_ASN1_VALUE_new_null(); |
291 | if (!skval) | 291 | if (!skval) |
292 | { | 292 | { |
293 | ASN1err(ASN1_F_ASN1_TEMPLATE_NEW, ERR_R_MALLOC_FAILURE); | 293 | ASN1err(ASN1_F_ASN1_TEMPLATE_NEW, ERR_R_MALLOC_FAILURE); |
294 | ret = 0; | 294 | ret = 0; |
295 | goto done; | 295 | goto done; |
296 | } | 296 | } |
297 | *pval = (ASN1_VALUE *)skval; | 297 | *pval = (ASN1_VALUE *)skval; |
298 | ret = 1; | 298 | ret = 1; |
299 | goto done; | 299 | goto done; |
300 | } | 300 | } |
301 | /* Otherwise pass it back to the item routine */ | 301 | /* Otherwise pass it back to the item routine */ |
302 | ret = asn1_item_ex_combine_new(pval, it, tt->flags & ASN1_TFLG_COMBINE); | 302 | ret = asn1_item_ex_combine_new(pval, it, tt->flags & ASN1_TFLG_COMBINE); |
303 | done: | 303 | done: |
@@ -306,16 +306,16 @@ int ASN1_template_new(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) | |||
306 | CRYPTO_pop_info(); | 306 | CRYPTO_pop_info(); |
307 | #endif | 307 | #endif |
308 | return ret; | 308 | return ret; |
309 | } | 309 | } |
310 | 310 | ||
311 | static void asn1_template_clear(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) | 311 | static void asn1_template_clear(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) |
312 | { | 312 | { |
313 | /* If ADB or STACK just NULL the field */ | 313 | /* If ADB or STACK just NULL the field */ |
314 | if (tt->flags & (ASN1_TFLG_ADB_MASK|ASN1_TFLG_SK_MASK)) | 314 | if (tt->flags & (ASN1_TFLG_ADB_MASK|ASN1_TFLG_SK_MASK)) |
315 | *pval = NULL; | 315 | *pval = NULL; |
316 | else | 316 | else |
317 | asn1_item_clear(pval, ASN1_ITEM_ptr(tt->item)); | 317 | asn1_item_clear(pval, ASN1_ITEM_ptr(tt->item)); |
318 | } | 318 | } |
319 | 319 | ||
320 | 320 | ||
321 | /* NB: could probably combine most of the real XXX_new() behaviour and junk | 321 | /* NB: could probably combine most of the real XXX_new() behaviour and junk |
@@ -323,24 +323,24 @@ static void asn1_template_clear(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) | |||
323 | */ | 323 | */ |
324 | 324 | ||
325 | int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it) | 325 | int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it) |
326 | { | 326 | { |
327 | ASN1_TYPE *typ; | 327 | ASN1_TYPE *typ; |
328 | ASN1_STRING *str; | 328 | ASN1_STRING *str; |
329 | int utype; | 329 | int utype; |
330 | 330 | ||
331 | if (it && it->funcs) | 331 | if (it && it->funcs) |
332 | { | 332 | { |
333 | const ASN1_PRIMITIVE_FUNCS *pf = it->funcs; | 333 | const ASN1_PRIMITIVE_FUNCS *pf = it->funcs; |
334 | if (pf->prim_new) | 334 | if (pf->prim_new) |
335 | return pf->prim_new(pval, it); | 335 | return pf->prim_new(pval, it); |
336 | } | 336 | } |
337 | 337 | ||
338 | if (!it || (it->itype == ASN1_ITYPE_MSTRING)) | 338 | if (!it || (it->itype == ASN1_ITYPE_MSTRING)) |
339 | utype = -1; | 339 | utype = -1; |
340 | else | 340 | else |
341 | utype = it->utype; | 341 | utype = it->utype; |
342 | switch(utype) | 342 | switch(utype) |
343 | { | 343 | { |
344 | case V_ASN1_OBJECT: | 344 | case V_ASN1_OBJECT: |
345 | *pval = (ASN1_VALUE *)OBJ_nid2obj(NID_undef); | 345 | *pval = (ASN1_VALUE *)OBJ_nid2obj(NID_undef); |
346 | return 1; | 346 | return 1; |
@@ -368,24 +368,24 @@ int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it) | |||
368 | str->flags |= ASN1_STRING_FLAG_MSTRING; | 368 | str->flags |= ASN1_STRING_FLAG_MSTRING; |
369 | *pval = (ASN1_VALUE *)str; | 369 | *pval = (ASN1_VALUE *)str; |
370 | break; | 370 | break; |
371 | } | 371 | } |
372 | if (*pval) | 372 | if (*pval) |
373 | return 1; | 373 | return 1; |
374 | return 0; | 374 | return 0; |
375 | } | 375 | } |
376 | 376 | ||
377 | static void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it) | 377 | static void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it) |
378 | { | 378 | { |
379 | int utype; | 379 | int utype; |
380 | if (it && it->funcs) | 380 | if (it && it->funcs) |
381 | { | 381 | { |
382 | const ASN1_PRIMITIVE_FUNCS *pf = it->funcs; | 382 | const ASN1_PRIMITIVE_FUNCS *pf = it->funcs; |
383 | if (pf->prim_clear) | 383 | if (pf->prim_clear) |
384 | pf->prim_clear(pval, it); | 384 | pf->prim_clear(pval, it); |
385 | else | 385 | else |
386 | *pval = NULL; | 386 | *pval = NULL; |
387 | return; | 387 | return; |
388 | } | 388 | } |
389 | if (!it || (it->itype == ASN1_ITYPE_MSTRING)) | 389 | if (!it || (it->itype == ASN1_ITYPE_MSTRING)) |
390 | utype = -1; | 390 | utype = -1; |
391 | else | 391 | else |
@@ -393,4 +393,4 @@ static void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it) | |||
393 | if (utype == V_ASN1_BOOLEAN) | 393 | if (utype == V_ASN1_BOOLEAN) |
394 | *(ASN1_BOOLEAN *)pval = it->size; | 394 | *(ASN1_BOOLEAN *)pval = it->size; |
395 | else *pval = NULL; | 395 | else *pval = NULL; |
396 | } | 396 | } |
diff --git a/src/lib/libcrypto/asn1/tasn_prn.c b/src/lib/libcrypto/asn1/tasn_prn.c index ec524edac8..f62c085f3b 100644 --- a/src/lib/libcrypto/asn1/tasn_prn.c +++ b/src/lib/libcrypto/asn1/tasn_prn.c | |||
@@ -73,86 +73,86 @@ | |||
73 | /* ASN1_PCTX routines */ | 73 | /* ASN1_PCTX routines */ |
74 | 74 | ||
75 | ASN1_PCTX default_pctx = | 75 | ASN1_PCTX default_pctx = |
76 | { | 76 | { |
77 | ASN1_PCTX_FLAGS_SHOW_ABSENT, /* flags */ | 77 | ASN1_PCTX_FLAGS_SHOW_ABSENT, /* flags */ |
78 | 0, /* nm_flags */ | 78 | 0, /* nm_flags */ |
79 | 0, /* cert_flags */ | 79 | 0, /* cert_flags */ |
80 | 0, /* oid_flags */ | 80 | 0, /* oid_flags */ |
81 | 0 /* str_flags */ | 81 | 0 /* str_flags */ |
82 | }; | 82 | }; |
83 | 83 | ||
84 | 84 | ||
85 | ASN1_PCTX *ASN1_PCTX_new(void) | 85 | ASN1_PCTX *ASN1_PCTX_new(void) |
86 | { | 86 | { |
87 | ASN1_PCTX *ret; | 87 | ASN1_PCTX *ret; |
88 | ret = malloc(sizeof(ASN1_PCTX)); | 88 | ret = malloc(sizeof(ASN1_PCTX)); |
89 | if (ret == NULL) | 89 | if (ret == NULL) |
90 | { | 90 | { |
91 | ASN1err(ASN1_F_ASN1_PCTX_NEW, ERR_R_MALLOC_FAILURE); | 91 | ASN1err(ASN1_F_ASN1_PCTX_NEW, ERR_R_MALLOC_FAILURE); |
92 | return NULL; | 92 | return NULL; |
93 | } | 93 | } |
94 | ret->flags = 0; | 94 | ret->flags = 0; |
95 | ret->nm_flags = 0; | 95 | ret->nm_flags = 0; |
96 | ret->cert_flags = 0; | 96 | ret->cert_flags = 0; |
97 | ret->oid_flags = 0; | 97 | ret->oid_flags = 0; |
98 | ret->str_flags = 0; | 98 | ret->str_flags = 0; |
99 | return ret; | 99 | return ret; |
100 | } | 100 | } |
101 | 101 | ||
102 | void ASN1_PCTX_free(ASN1_PCTX *p) | 102 | void ASN1_PCTX_free(ASN1_PCTX *p) |
103 | { | 103 | { |
104 | free(p); | 104 | free(p); |
105 | } | 105 | } |
106 | 106 | ||
107 | unsigned long ASN1_PCTX_get_flags(ASN1_PCTX *p) | 107 | unsigned long ASN1_PCTX_get_flags(ASN1_PCTX *p) |
108 | { | 108 | { |
109 | return p->flags; | 109 | return p->flags; |
110 | } | 110 | } |
111 | 111 | ||
112 | void ASN1_PCTX_set_flags(ASN1_PCTX *p, unsigned long flags) | 112 | void ASN1_PCTX_set_flags(ASN1_PCTX *p, unsigned long flags) |
113 | { | 113 | { |
114 | p->flags = flags; | 114 | p->flags = flags; |
115 | } | 115 | } |
116 | 116 | ||
117 | unsigned long ASN1_PCTX_get_nm_flags(ASN1_PCTX *p) | 117 | unsigned long ASN1_PCTX_get_nm_flags(ASN1_PCTX *p) |
118 | { | 118 | { |
119 | return p->nm_flags; | 119 | return p->nm_flags; |
120 | } | 120 | } |
121 | 121 | ||
122 | void ASN1_PCTX_set_nm_flags(ASN1_PCTX *p, unsigned long flags) | 122 | void ASN1_PCTX_set_nm_flags(ASN1_PCTX *p, unsigned long flags) |
123 | { | 123 | { |
124 | p->nm_flags = flags; | 124 | p->nm_flags = flags; |
125 | } | 125 | } |
126 | 126 | ||
127 | unsigned long ASN1_PCTX_get_cert_flags(ASN1_PCTX *p) | 127 | unsigned long ASN1_PCTX_get_cert_flags(ASN1_PCTX *p) |
128 | { | 128 | { |
129 | return p->cert_flags; | 129 | return p->cert_flags; |
130 | } | 130 | } |
131 | 131 | ||
132 | void ASN1_PCTX_set_cert_flags(ASN1_PCTX *p, unsigned long flags) | 132 | void ASN1_PCTX_set_cert_flags(ASN1_PCTX *p, unsigned long flags) |
133 | { | 133 | { |
134 | p->cert_flags = flags; | 134 | p->cert_flags = flags; |
135 | } | 135 | } |
136 | 136 | ||
137 | unsigned long ASN1_PCTX_get_oid_flags(ASN1_PCTX *p) | 137 | unsigned long ASN1_PCTX_get_oid_flags(ASN1_PCTX *p) |
138 | { | 138 | { |
139 | return p->oid_flags; | 139 | return p->oid_flags; |
140 | } | 140 | } |
141 | 141 | ||
142 | void ASN1_PCTX_set_oid_flags(ASN1_PCTX *p, unsigned long flags) | 142 | void ASN1_PCTX_set_oid_flags(ASN1_PCTX *p, unsigned long flags) |
143 | { | 143 | { |
144 | p->oid_flags = flags; | 144 | p->oid_flags = flags; |
145 | } | 145 | } |
146 | 146 | ||
147 | unsigned long ASN1_PCTX_get_str_flags(ASN1_PCTX *p) | 147 | unsigned long ASN1_PCTX_get_str_flags(ASN1_PCTX *p) |
148 | { | 148 | { |
149 | return p->str_flags; | 149 | return p->str_flags; |
150 | } | 150 | } |
151 | 151 | ||
152 | void ASN1_PCTX_set_str_flags(ASN1_PCTX *p, unsigned long flags) | 152 | void ASN1_PCTX_set_str_flags(ASN1_PCTX *p, unsigned long flags) |
153 | { | 153 | { |
154 | p->str_flags = flags; | 154 | p->str_flags = flags; |
155 | } | 155 | } |
156 | 156 | ||
157 | /* Main print routines */ | 157 | /* Main print routines */ |
158 | 158 | ||
@@ -175,7 +175,7 @@ static int asn1_print_fsname(BIO *out, int indent, | |||
175 | 175 | ||
176 | int ASN1_item_print(BIO *out, ASN1_VALUE *ifld, int indent, | 176 | int ASN1_item_print(BIO *out, ASN1_VALUE *ifld, int indent, |
177 | const ASN1_ITEM *it, const ASN1_PCTX *pctx) | 177 | const ASN1_ITEM *it, const ASN1_PCTX *pctx) |
178 | { | 178 | { |
179 | const char *sname; | 179 | const char *sname; |
180 | if (pctx == NULL) | 180 | if (pctx == NULL) |
181 | pctx = &default_pctx; | 181 | pctx = &default_pctx; |
@@ -185,13 +185,13 @@ int ASN1_item_print(BIO *out, ASN1_VALUE *ifld, int indent, | |||
185 | sname = it->sname; | 185 | sname = it->sname; |
186 | return asn1_item_print_ctx(out, &ifld, indent, it, | 186 | return asn1_item_print_ctx(out, &ifld, indent, it, |
187 | NULL, sname, 0, pctx); | 187 | NULL, sname, 0, pctx); |
188 | } | 188 | } |
189 | 189 | ||
190 | static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent, | 190 | static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent, |
191 | const ASN1_ITEM *it, | 191 | const ASN1_ITEM *it, |
192 | const char *fname, const char *sname, | 192 | const char *fname, const char *sname, |
193 | int nohdr, const ASN1_PCTX *pctx) | 193 | int nohdr, const ASN1_PCTX *pctx) |
194 | { | 194 | { |
195 | const ASN1_TEMPLATE *tt; | 195 | const ASN1_TEMPLATE *tt; |
196 | const ASN1_EXTERN_FUNCS *ef; | 196 | const ASN1_EXTERN_FUNCS *ef; |
197 | ASN1_VALUE **tmpfld; | 197 | ASN1_VALUE **tmpfld; |
@@ -200,36 +200,36 @@ static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent, | |||
200 | ASN1_PRINT_ARG parg; | 200 | ASN1_PRINT_ARG parg; |
201 | int i; | 201 | int i; |
202 | if (aux && aux->asn1_cb) | 202 | if (aux && aux->asn1_cb) |
203 | { | 203 | { |
204 | parg.out = out; | 204 | parg.out = out; |
205 | parg.indent = indent; | 205 | parg.indent = indent; |
206 | parg.pctx = pctx; | 206 | parg.pctx = pctx; |
207 | asn1_cb = aux->asn1_cb; | 207 | asn1_cb = aux->asn1_cb; |
208 | } | 208 | } |
209 | else asn1_cb = 0; | 209 | else asn1_cb = 0; |
210 | 210 | ||
211 | if(*fld == NULL) | 211 | if(*fld == NULL) |
212 | { | 212 | { |
213 | if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_ABSENT) | 213 | if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_ABSENT) |
214 | { | 214 | { |
215 | if (!nohdr && !asn1_print_fsname(out, indent, | 215 | if (!nohdr && !asn1_print_fsname(out, indent, |
216 | fname, sname, pctx)) | 216 | fname, sname, pctx)) |
217 | return 0; | 217 | return 0; |
218 | if (BIO_puts(out, "<ABSENT>\n") <= 0) | 218 | if (BIO_puts(out, "<ABSENT>\n") <= 0) |
219 | return 0; | 219 | return 0; |
220 | } | ||
221 | return 1; | ||
222 | } | 220 | } |
221 | return 1; | ||
222 | } | ||
223 | 223 | ||
224 | switch(it->itype) | 224 | switch(it->itype) |
225 | { | 225 | { |
226 | case ASN1_ITYPE_PRIMITIVE: | 226 | case ASN1_ITYPE_PRIMITIVE: |
227 | if(it->templates) | 227 | if(it->templates) |
228 | { | 228 | { |
229 | if (!asn1_template_print_ctx(out, fld, indent, | 229 | if (!asn1_template_print_ctx(out, fld, indent, |
230 | it->templates, pctx)) | 230 | it->templates, pctx)) |
231 | return 0; | 231 | return 0; |
232 | } | 232 | } |
233 | /* fall thru */ | 233 | /* fall thru */ |
234 | case ASN1_ITYPE_MSTRING: | 234 | case ASN1_ITYPE_MSTRING: |
235 | if (!asn1_primitive_print(out, fld, it, | 235 | if (!asn1_primitive_print(out, fld, it, |
@@ -243,14 +243,14 @@ static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent, | |||
243 | /* Use new style print routine if possible */ | 243 | /* Use new style print routine if possible */ |
244 | ef = it->funcs; | 244 | ef = it->funcs; |
245 | if (ef && ef->asn1_ex_print) | 245 | if (ef && ef->asn1_ex_print) |
246 | { | 246 | { |
247 | i = ef->asn1_ex_print(out, fld, indent, "", pctx); | 247 | i = ef->asn1_ex_print(out, fld, indent, "", pctx); |
248 | if (!i) | 248 | if (!i) |
249 | return 0; | 249 | return 0; |
250 | if ((i == 2) && (BIO_puts(out, "\n") <= 0)) | 250 | if ((i == 2) && (BIO_puts(out, "\n") <= 0)) |
251 | return 0; | 251 | return 0; |
252 | return 1; | 252 | return 1; |
253 | } | 253 | } |
254 | else if (sname && | 254 | else if (sname && |
255 | BIO_printf(out, ":EXTERNAL TYPE %s\n", sname) <= 0) | 255 | BIO_printf(out, ":EXTERNAL TYPE %s\n", sname) <= 0) |
256 | return 0; | 256 | return 0; |
@@ -265,12 +265,12 @@ static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent, | |||
265 | i = asn1_get_choice_selector(fld, it); | 265 | i = asn1_get_choice_selector(fld, it); |
266 | /* This should never happen... */ | 266 | /* This should never happen... */ |
267 | if((i < 0) || (i >= it->tcount)) | 267 | if((i < 0) || (i >= it->tcount)) |
268 | { | 268 | { |
269 | if (BIO_printf(out, | 269 | if (BIO_printf(out, |
270 | "ERROR: selector [%d] invalid\n", i) <= 0) | 270 | "ERROR: selector [%d] invalid\n", i) <= 0) |
271 | return 0; | 271 | return 0; |
272 | return 1; | 272 | return 1; |
273 | } | 273 | } |
274 | tt = it->templates + i; | 274 | tt = it->templates + i; |
275 | tmpfld = asn1_get_field_ptr(fld, tt); | 275 | tmpfld = asn1_get_field_ptr(fld, tt); |
276 | if (!asn1_template_print_ctx(out, tmpfld, indent, tt, pctx)) | 276 | if (!asn1_template_print_ctx(out, tmpfld, indent, tt, pctx)) |
@@ -282,63 +282,63 @@ static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent, | |||
282 | if (!nohdr && !asn1_print_fsname(out, indent, fname, sname, pctx)) | 282 | if (!nohdr && !asn1_print_fsname(out, indent, fname, sname, pctx)) |
283 | return 0; | 283 | return 0; |
284 | if (fname || sname) | 284 | if (fname || sname) |
285 | { | 285 | { |
286 | if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_SEQUENCE) | 286 | if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_SEQUENCE) |
287 | { | 287 | { |
288 | if (BIO_puts(out, " {\n") <= 0) | 288 | if (BIO_puts(out, " {\n") <= 0) |
289 | return 0; | 289 | return 0; |
290 | } | 290 | } |
291 | else | 291 | else |
292 | { | 292 | { |
293 | if (BIO_puts(out, "\n") <= 0) | 293 | if (BIO_puts(out, "\n") <= 0) |
294 | return 0; | 294 | return 0; |
295 | } | ||
296 | } | 295 | } |
296 | } | ||
297 | 297 | ||
298 | if (asn1_cb) | 298 | if (asn1_cb) |
299 | { | 299 | { |
300 | i = asn1_cb(ASN1_OP_PRINT_PRE, fld, it, &parg); | 300 | i = asn1_cb(ASN1_OP_PRINT_PRE, fld, it, &parg); |
301 | if (i == 0) | 301 | if (i == 0) |
302 | return 0; | 302 | return 0; |
303 | if (i == 2) | 303 | if (i == 2) |
304 | return 1; | 304 | return 1; |
305 | } | 305 | } |
306 | 306 | ||
307 | /* Print each field entry */ | 307 | /* Print each field entry */ |
308 | for(i = 0, tt = it->templates; i < it->tcount; i++, tt++) | 308 | for(i = 0, tt = it->templates; i < it->tcount; i++, tt++) |
309 | { | 309 | { |
310 | const ASN1_TEMPLATE *seqtt; | 310 | const ASN1_TEMPLATE *seqtt; |
311 | seqtt = asn1_do_adb(fld, tt, 1); | 311 | seqtt = asn1_do_adb(fld, tt, 1); |
312 | tmpfld = asn1_get_field_ptr(fld, seqtt); | 312 | tmpfld = asn1_get_field_ptr(fld, seqtt); |
313 | if (!asn1_template_print_ctx(out, tmpfld, | 313 | if (!asn1_template_print_ctx(out, tmpfld, |
314 | indent + 2, seqtt, pctx)) | 314 | indent + 2, seqtt, pctx)) |
315 | return 0; | 315 | return 0; |
316 | } | 316 | } |
317 | if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_SEQUENCE) | 317 | if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_SEQUENCE) |
318 | { | 318 | { |
319 | if (BIO_printf(out, "%*s}\n", indent, "") < 0) | 319 | if (BIO_printf(out, "%*s}\n", indent, "") < 0) |
320 | return 0; | 320 | return 0; |
321 | } | 321 | } |
322 | 322 | ||
323 | if (asn1_cb) | 323 | if (asn1_cb) |
324 | { | 324 | { |
325 | i = asn1_cb(ASN1_OP_PRINT_POST, fld, it, &parg); | 325 | i = asn1_cb(ASN1_OP_PRINT_POST, fld, it, &parg); |
326 | if (i == 0) | 326 | if (i == 0) |
327 | return 0; | 327 | return 0; |
328 | } | 328 | } |
329 | break; | 329 | break; |
330 | 330 | ||
331 | default: | 331 | default: |
332 | BIO_printf(out, "Unprocessed type %d\n", it->itype); | 332 | BIO_printf(out, "Unprocessed type %d\n", it->itype); |
333 | return 0; | 333 | return 0; |
334 | } | 334 | } |
335 | 335 | ||
336 | return 1; | 336 | return 1; |
337 | } | 337 | } |
338 | 338 | ||
339 | int asn1_template_print_ctx(BIO *out, ASN1_VALUE **fld, int indent, | 339 | int asn1_template_print_ctx(BIO *out, ASN1_VALUE **fld, int indent, |
340 | const ASN1_TEMPLATE *tt, const ASN1_PCTX *pctx) | 340 | const ASN1_TEMPLATE *tt, const ASN1_PCTX *pctx) |
341 | { | 341 | { |
342 | int i, flags; | 342 | int i, flags; |
343 | const char *sname, *fname; | 343 | const char *sname, *fname; |
344 | flags = tt->flags; | 344 | flags = tt->flags; |
@@ -351,16 +351,16 @@ int asn1_template_print_ctx(BIO *out, ASN1_VALUE **fld, int indent, | |||
351 | else | 351 | else |
352 | fname = tt->field_name; | 352 | fname = tt->field_name; |
353 | if(flags & ASN1_TFLG_SK_MASK) | 353 | if(flags & ASN1_TFLG_SK_MASK) |
354 | { | 354 | { |
355 | char *tname; | 355 | char *tname; |
356 | ASN1_VALUE *skitem; | 356 | ASN1_VALUE *skitem; |
357 | STACK_OF(ASN1_VALUE) *stack; | 357 | STACK_OF(ASN1_VALUE) *stack; |
358 | 358 | ||
359 | /* SET OF, SEQUENCE OF */ | 359 | /* SET OF, SEQUENCE OF */ |
360 | if (fname) | 360 | if (fname) |
361 | { | 361 | { |
362 | if(pctx->flags & ASN1_PCTX_FLAGS_SHOW_SSOF) | 362 | if(pctx->flags & ASN1_PCTX_FLAGS_SHOW_SSOF) |
363 | { | 363 | { |
364 | if(flags & ASN1_TFLG_SET_OF) | 364 | if(flags & ASN1_TFLG_SET_OF) |
365 | tname = "SET"; | 365 | tname = "SET"; |
366 | else | 366 | else |
@@ -368,14 +368,14 @@ int asn1_template_print_ctx(BIO *out, ASN1_VALUE **fld, int indent, | |||
368 | if (BIO_printf(out, "%*s%s OF %s {\n", | 368 | if (BIO_printf(out, "%*s%s OF %s {\n", |
369 | indent, "", tname, tt->field_name) <= 0) | 369 | indent, "", tname, tt->field_name) <= 0) |
370 | return 0; | 370 | return 0; |
371 | } | 371 | } |
372 | else if (BIO_printf(out, "%*s%s:\n", indent, "", | 372 | else if (BIO_printf(out, "%*s%s:\n", indent, "", |
373 | fname) <= 0) | 373 | fname) <= 0) |
374 | return 0; | 374 | return 0; |
375 | } | 375 | } |
376 | stack = (STACK_OF(ASN1_VALUE) *)*fld; | 376 | stack = (STACK_OF(ASN1_VALUE) *)*fld; |
377 | for(i = 0; i < sk_ASN1_VALUE_num(stack); i++) | 377 | for(i = 0; i < sk_ASN1_VALUE_num(stack); i++) |
378 | { | 378 | { |
379 | if ((i > 0) && (BIO_puts(out, "\n") <= 0)) | 379 | if ((i > 0) && (BIO_puts(out, "\n") <= 0)) |
380 | return 0; | 380 | return 0; |
381 | 381 | ||
@@ -383,24 +383,24 @@ int asn1_template_print_ctx(BIO *out, ASN1_VALUE **fld, int indent, | |||
383 | if (!asn1_item_print_ctx(out, &skitem, indent + 2, | 383 | if (!asn1_item_print_ctx(out, &skitem, indent + 2, |
384 | ASN1_ITEM_ptr(tt->item), NULL, NULL, 1, pctx)) | 384 | ASN1_ITEM_ptr(tt->item), NULL, NULL, 1, pctx)) |
385 | return 0; | 385 | return 0; |
386 | } | 386 | } |
387 | if (!i && BIO_printf(out, "%*s<EMPTY>\n", indent + 2, "") <= 0) | 387 | if (!i && BIO_printf(out, "%*s<EMPTY>\n", indent + 2, "") <= 0) |
388 | return 0; | 388 | return 0; |
389 | if(pctx->flags & ASN1_PCTX_FLAGS_SHOW_SEQUENCE) | 389 | if(pctx->flags & ASN1_PCTX_FLAGS_SHOW_SEQUENCE) |
390 | { | 390 | { |
391 | if (BIO_printf(out, "%*s}\n", indent, "") <= 0) | 391 | if (BIO_printf(out, "%*s}\n", indent, "") <= 0) |
392 | return 0; | 392 | return 0; |
393 | } | ||
394 | return 1; | ||
395 | } | 393 | } |
394 | return 1; | ||
395 | } | ||
396 | return asn1_item_print_ctx(out, fld, indent, ASN1_ITEM_ptr(tt->item), | 396 | return asn1_item_print_ctx(out, fld, indent, ASN1_ITEM_ptr(tt->item), |
397 | fname, sname, 0, pctx); | 397 | fname, sname, 0, pctx); |
398 | } | 398 | } |
399 | 399 | ||
400 | static int asn1_print_fsname(BIO *out, int indent, | 400 | static int asn1_print_fsname(BIO *out, int indent, |
401 | const char *fname, const char *sname, | 401 | const char *fname, const char *sname, |
402 | const ASN1_PCTX *pctx) | 402 | const ASN1_PCTX *pctx) |
403 | { | 403 | { |
404 | static char spaces[] = " "; | 404 | static char spaces[] = " "; |
405 | const int nspaces = sizeof(spaces) - 1; | 405 | const int nspaces = sizeof(spaces) - 1; |
406 | 406 | ||
@@ -410,11 +410,11 @@ static int asn1_print_fsname(BIO *out, int indent, | |||
410 | #endif | 410 | #endif |
411 | 411 | ||
412 | while (indent > nspaces) | 412 | while (indent > nspaces) |
413 | { | 413 | { |
414 | if (BIO_write(out, spaces, nspaces) != nspaces) | 414 | if (BIO_write(out, spaces, nspaces) != nspaces) |
415 | return 0; | 415 | return 0; |
416 | indent -= nspaces; | 416 | indent -= nspaces; |
417 | } | 417 | } |
418 | if (BIO_write(out, spaces, indent) != indent) | 418 | if (BIO_write(out, spaces, indent) != indent) |
419 | return 0; | 419 | return 0; |
420 | if (pctx->flags & ASN1_PCTX_FLAGS_NO_STRUCT_NAME) | 420 | if (pctx->flags & ASN1_PCTX_FLAGS_NO_STRUCT_NAME) |
@@ -424,34 +424,34 @@ static int asn1_print_fsname(BIO *out, int indent, | |||
424 | if (!sname && !fname) | 424 | if (!sname && !fname) |
425 | return 1; | 425 | return 1; |
426 | if (fname) | 426 | if (fname) |
427 | { | 427 | { |
428 | if (BIO_puts(out, fname) <= 0) | 428 | if (BIO_puts(out, fname) <= 0) |
429 | return 0; | 429 | return 0; |
430 | } | 430 | } |
431 | if (sname) | 431 | if (sname) |
432 | { | 432 | { |
433 | if (fname) | 433 | if (fname) |
434 | { | 434 | { |
435 | if (BIO_printf(out, " (%s)", sname) <= 0) | 435 | if (BIO_printf(out, " (%s)", sname) <= 0) |
436 | return 0; | 436 | return 0; |
437 | } | 437 | } |
438 | else | 438 | else |
439 | { | 439 | { |
440 | if (BIO_puts(out, sname) <= 0) | 440 | if (BIO_puts(out, sname) <= 0) |
441 | return 0; | 441 | return 0; |
442 | } | ||
443 | } | 442 | } |
443 | } | ||
444 | if (BIO_write(out, ": ", 2) != 2) | 444 | if (BIO_write(out, ": ", 2) != 2) |
445 | return 0; | 445 | return 0; |
446 | return 1; | 446 | return 1; |
447 | } | 447 | } |
448 | 448 | ||
449 | static int asn1_print_boolean_ctx(BIO *out, int boolval, | 449 | static int asn1_print_boolean_ctx(BIO *out, int boolval, |
450 | const ASN1_PCTX *pctx) | 450 | const ASN1_PCTX *pctx) |
451 | { | 451 | { |
452 | const char *str; | 452 | const char *str; |
453 | switch (boolval) | 453 | switch (boolval) |
454 | { | 454 | { |
455 | case -1: | 455 | case -1: |
456 | str = "BOOL ABSENT"; | 456 | str = "BOOL ABSENT"; |
457 | break; | 457 | break; |
@@ -464,17 +464,17 @@ static int asn1_print_boolean_ctx(BIO *out, int boolval, | |||
464 | str = "TRUE"; | 464 | str = "TRUE"; |
465 | break; | 465 | break; |
466 | 466 | ||
467 | } | 467 | } |
468 | 468 | ||
469 | if (BIO_puts(out, str) <= 0) | 469 | if (BIO_puts(out, str) <= 0) |
470 | return 0; | 470 | return 0; |
471 | return 1; | 471 | return 1; |
472 | 472 | ||
473 | } | 473 | } |
474 | 474 | ||
475 | static int asn1_print_integer_ctx(BIO *out, ASN1_INTEGER *str, | 475 | static int asn1_print_integer_ctx(BIO *out, ASN1_INTEGER *str, |
476 | const ASN1_PCTX *pctx) | 476 | const ASN1_PCTX *pctx) |
477 | { | 477 | { |
478 | char *s; | 478 | char *s; |
479 | int ret = 1; | 479 | int ret = 1; |
480 | s = i2s_ASN1_INTEGER(NULL, str); | 480 | s = i2s_ASN1_INTEGER(NULL, str); |
@@ -482,11 +482,11 @@ static int asn1_print_integer_ctx(BIO *out, ASN1_INTEGER *str, | |||
482 | ret = 0; | 482 | ret = 0; |
483 | free(s); | 483 | free(s); |
484 | return ret; | 484 | return ret; |
485 | } | 485 | } |
486 | 486 | ||
487 | static int asn1_print_oid_ctx(BIO *out, const ASN1_OBJECT *oid, | 487 | static int asn1_print_oid_ctx(BIO *out, const ASN1_OBJECT *oid, |
488 | const ASN1_PCTX *pctx) | 488 | const ASN1_PCTX *pctx) |
489 | { | 489 | { |
490 | char objbuf[80]; | 490 | char objbuf[80]; |
491 | const char *ln; | 491 | const char *ln; |
492 | ln = OBJ_nid2ln(OBJ_obj2nid(oid)); | 492 | ln = OBJ_nid2ln(OBJ_obj2nid(oid)); |
@@ -496,17 +496,17 @@ static int asn1_print_oid_ctx(BIO *out, const ASN1_OBJECT *oid, | |||
496 | if (BIO_printf(out, "%s (%s)", ln, objbuf) <= 0) | 496 | if (BIO_printf(out, "%s (%s)", ln, objbuf) <= 0) |
497 | return 0; | 497 | return 0; |
498 | return 1; | 498 | return 1; |
499 | } | 499 | } |
500 | 500 | ||
501 | static int asn1_print_obstring_ctx(BIO *out, ASN1_STRING *str, int indent, | 501 | static int asn1_print_obstring_ctx(BIO *out, ASN1_STRING *str, int indent, |
502 | const ASN1_PCTX *pctx) | 502 | const ASN1_PCTX *pctx) |
503 | { | 503 | { |
504 | if (str->type == V_ASN1_BIT_STRING) | 504 | if (str->type == V_ASN1_BIT_STRING) |
505 | { | 505 | { |
506 | if (BIO_printf(out, " (%ld unused bits)\n", | 506 | if (BIO_printf(out, " (%ld unused bits)\n", |
507 | str->flags & 0x7) <= 0) | 507 | str->flags & 0x7) <= 0) |
508 | return 0; | 508 | return 0; |
509 | } | 509 | } |
510 | else if (BIO_puts(out, "\n") <= 0) | 510 | else if (BIO_puts(out, "\n") <= 0) |
511 | return 0; | 511 | return 0; |
512 | if ((str->length > 0) | 512 | if ((str->length > 0) |
@@ -514,13 +514,13 @@ static int asn1_print_obstring_ctx(BIO *out, ASN1_STRING *str, int indent, | |||
514 | indent + 2) <= 0) | 514 | indent + 2) <= 0) |
515 | return 0; | 515 | return 0; |
516 | return 1; | 516 | return 1; |
517 | } | 517 | } |
518 | 518 | ||
519 | static int asn1_primitive_print(BIO *out, ASN1_VALUE **fld, | 519 | static int asn1_primitive_print(BIO *out, ASN1_VALUE **fld, |
520 | const ASN1_ITEM *it, int indent, | 520 | const ASN1_ITEM *it, int indent, |
521 | const char *fname, const char *sname, | 521 | const char *fname, const char *sname, |
522 | const ASN1_PCTX *pctx) | 522 | const ASN1_PCTX *pctx) |
523 | { | 523 | { |
524 | long utype; | 524 | long utype; |
525 | ASN1_STRING *str; | 525 | ASN1_STRING *str; |
526 | int ret = 1, needlf = 1; | 526 | int ret = 1, needlf = 1; |
@@ -537,7 +537,7 @@ static int asn1_primitive_print(BIO *out, ASN1_VALUE **fld, | |||
537 | else | 537 | else |
538 | utype = it->utype; | 538 | utype = it->utype; |
539 | if (utype == V_ASN1_ANY) | 539 | if (utype == V_ASN1_ANY) |
540 | { | 540 | { |
541 | ASN1_TYPE *atype = (ASN1_TYPE *)*fld; | 541 | ASN1_TYPE *atype = (ASN1_TYPE *)*fld; |
542 | utype = atype->type; | 542 | utype = atype->type; |
543 | fld = &atype->value.asn1_value; | 543 | fld = &atype->value.asn1_value; |
@@ -546,39 +546,39 @@ static int asn1_primitive_print(BIO *out, ASN1_VALUE **fld, | |||
546 | pname = NULL; | 546 | pname = NULL; |
547 | else | 547 | else |
548 | pname = ASN1_tag2str(utype); | 548 | pname = ASN1_tag2str(utype); |
549 | } | 549 | } |
550 | else | 550 | else |
551 | { | 551 | { |
552 | if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_TYPE) | 552 | if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_TYPE) |
553 | pname = ASN1_tag2str(utype); | 553 | pname = ASN1_tag2str(utype); |
554 | else | 554 | else |
555 | pname = NULL; | 555 | pname = NULL; |
556 | } | 556 | } |
557 | 557 | ||
558 | if (utype == V_ASN1_NULL) | 558 | if (utype == V_ASN1_NULL) |
559 | { | 559 | { |
560 | if (BIO_puts(out, "NULL\n") <= 0) | 560 | if (BIO_puts(out, "NULL\n") <= 0) |
561 | return 0; | 561 | return 0; |
562 | return 1; | 562 | return 1; |
563 | } | 563 | } |
564 | 564 | ||
565 | if (pname) | 565 | if (pname) |
566 | { | 566 | { |
567 | if (BIO_puts(out, pname) <= 0) | 567 | if (BIO_puts(out, pname) <= 0) |
568 | return 0; | 568 | return 0; |
569 | if (BIO_puts(out, ":") <= 0) | 569 | if (BIO_puts(out, ":") <= 0) |
570 | return 0; | 570 | return 0; |
571 | } | 571 | } |
572 | 572 | ||
573 | switch (utype) | 573 | switch (utype) |
574 | { | 574 | { |
575 | case V_ASN1_BOOLEAN: | 575 | case V_ASN1_BOOLEAN: |
576 | { | 576 | { |
577 | int boolval = *(int *)fld; | 577 | int boolval = *(int *)fld; |
578 | if (boolval == -1) | 578 | if (boolval == -1) |
579 | boolval = it->size; | 579 | boolval = it->size; |
580 | ret = asn1_print_boolean_ctx(out, boolval, pctx); | 580 | ret = asn1_print_boolean_ctx(out, boolval, pctx); |
581 | } | 581 | } |
582 | break; | 582 | break; |
583 | 583 | ||
584 | case V_ASN1_INTEGER: | 584 | case V_ASN1_INTEGER: |
@@ -618,10 +618,10 @@ static int asn1_primitive_print(BIO *out, ASN1_VALUE **fld, | |||
618 | default: | 618 | default: |
619 | ret = ASN1_STRING_print_ex(out, str, pctx->str_flags); | 619 | ret = ASN1_STRING_print_ex(out, str, pctx->str_flags); |
620 | 620 | ||
621 | } | 621 | } |
622 | if (!ret) | 622 | if (!ret) |
623 | return 0; | 623 | return 0; |
624 | if (needlf && BIO_puts(out, "\n") <= 0) | 624 | if (needlf && BIO_puts(out, "\n") <= 0) |
625 | return 0; | 625 | return 0; |
626 | return 1; | 626 | return 1; |
627 | } | 627 | } |
diff --git a/src/lib/libcrypto/asn1/tasn_utl.c b/src/lib/libcrypto/asn1/tasn_utl.c index ab4989b6ce..37c86c6af8 100644 --- a/src/lib/libcrypto/asn1/tasn_utl.c +++ b/src/lib/libcrypto/asn1/tasn_utl.c | |||
@@ -74,23 +74,23 @@ | |||
74 | */ | 74 | */ |
75 | 75 | ||
76 | int asn1_get_choice_selector(ASN1_VALUE **pval, const ASN1_ITEM *it) | 76 | int asn1_get_choice_selector(ASN1_VALUE **pval, const ASN1_ITEM *it) |
77 | { | 77 | { |
78 | int *sel = offset2ptr(*pval, it->utype); | 78 | int *sel = offset2ptr(*pval, it->utype); |
79 | return *sel; | 79 | return *sel; |
80 | } | 80 | } |
81 | 81 | ||
82 | /* Given an ASN1_ITEM CHOICE type set | 82 | /* Given an ASN1_ITEM CHOICE type set |
83 | * the selector value, return old value. | 83 | * the selector value, return old value. |
84 | */ | 84 | */ |
85 | 85 | ||
86 | int asn1_set_choice_selector(ASN1_VALUE **pval, int value, const ASN1_ITEM *it) | 86 | int asn1_set_choice_selector(ASN1_VALUE **pval, int value, const ASN1_ITEM *it) |
87 | { | 87 | { |
88 | int *sel, ret; | 88 | int *sel, ret; |
89 | sel = offset2ptr(*pval, it->utype); | 89 | sel = offset2ptr(*pval, it->utype); |
90 | ret = *sel; | 90 | ret = *sel; |
91 | *sel = value; | 91 | *sel = value; |
92 | return ret; | 92 | return ret; |
93 | } | 93 | } |
94 | 94 | ||
95 | /* Do reference counting. The value 'op' decides what to do. | 95 | /* Do reference counting. The value 'op' decides what to do. |
96 | * if it is +1 then the count is incremented. If op is 0 count is | 96 | * if it is +1 then the count is incremented. If op is 0 count is |
@@ -99,7 +99,7 @@ int asn1_set_choice_selector(ASN1_VALUE **pval, int value, const ASN1_ITEM *it) | |||
99 | */ | 99 | */ |
100 | 100 | ||
101 | int asn1_do_lock(ASN1_VALUE **pval, int op, const ASN1_ITEM *it) | 101 | int asn1_do_lock(ASN1_VALUE **pval, int op, const ASN1_ITEM *it) |
102 | { | 102 | { |
103 | const ASN1_AUX *aux; | 103 | const ASN1_AUX *aux; |
104 | int *lck, ret; | 104 | int *lck, ret; |
105 | if ((it->itype != ASN1_ITYPE_SEQUENCE) | 105 | if ((it->itype != ASN1_ITYPE_SEQUENCE) |
@@ -110,16 +110,16 @@ int asn1_do_lock(ASN1_VALUE **pval, int op, const ASN1_ITEM *it) | |||
110 | return 0; | 110 | return 0; |
111 | lck = offset2ptr(*pval, aux->ref_offset); | 111 | lck = offset2ptr(*pval, aux->ref_offset); |
112 | if (op == 0) | 112 | if (op == 0) |
113 | { | 113 | { |
114 | *lck = 1; | 114 | *lck = 1; |
115 | return 1; | 115 | return 1; |
116 | } | 116 | } |
117 | ret = CRYPTO_add(lck, op, aux->ref_lock); | 117 | ret = CRYPTO_add(lck, op, aux->ref_lock); |
118 | return ret; | 118 | return ret; |
119 | } | 119 | } |
120 | 120 | ||
121 | static ASN1_ENCODING *asn1_get_enc_ptr(ASN1_VALUE **pval, const ASN1_ITEM *it) | 121 | static ASN1_ENCODING *asn1_get_enc_ptr(ASN1_VALUE **pval, const ASN1_ITEM *it) |
122 | { | 122 | { |
123 | const ASN1_AUX *aux; | 123 | const ASN1_AUX *aux; |
124 | if (!pval || !*pval) | 124 | if (!pval || !*pval) |
125 | return NULL; | 125 | return NULL; |
@@ -127,37 +127,37 @@ static ASN1_ENCODING *asn1_get_enc_ptr(ASN1_VALUE **pval, const ASN1_ITEM *it) | |||
127 | if (!aux || !(aux->flags & ASN1_AFLG_ENCODING)) | 127 | if (!aux || !(aux->flags & ASN1_AFLG_ENCODING)) |
128 | return NULL; | 128 | return NULL; |
129 | return offset2ptr(*pval, aux->enc_offset); | 129 | return offset2ptr(*pval, aux->enc_offset); |
130 | } | 130 | } |
131 | 131 | ||
132 | void asn1_enc_init(ASN1_VALUE **pval, const ASN1_ITEM *it) | 132 | void asn1_enc_init(ASN1_VALUE **pval, const ASN1_ITEM *it) |
133 | { | 133 | { |
134 | ASN1_ENCODING *enc; | 134 | ASN1_ENCODING *enc; |
135 | enc = asn1_get_enc_ptr(pval, it); | 135 | enc = asn1_get_enc_ptr(pval, it); |
136 | if (enc) | 136 | if (enc) |
137 | { | 137 | { |
138 | enc->enc = NULL; | 138 | enc->enc = NULL; |
139 | enc->len = 0; | 139 | enc->len = 0; |
140 | enc->modified = 1; | 140 | enc->modified = 1; |
141 | } | ||
142 | } | 141 | } |
142 | } | ||
143 | 143 | ||
144 | void asn1_enc_free(ASN1_VALUE **pval, const ASN1_ITEM *it) | 144 | void asn1_enc_free(ASN1_VALUE **pval, const ASN1_ITEM *it) |
145 | { | 145 | { |
146 | ASN1_ENCODING *enc; | 146 | ASN1_ENCODING *enc; |
147 | enc = asn1_get_enc_ptr(pval, it); | 147 | enc = asn1_get_enc_ptr(pval, it); |
148 | if (enc) | 148 | if (enc) |
149 | { | 149 | { |
150 | if (enc->enc) | 150 | if (enc->enc) |
151 | free(enc->enc); | 151 | free(enc->enc); |
152 | enc->enc = NULL; | 152 | enc->enc = NULL; |
153 | enc->len = 0; | 153 | enc->len = 0; |
154 | enc->modified = 1; | 154 | enc->modified = 1; |
155 | } | ||
156 | } | 155 | } |
156 | } | ||
157 | 157 | ||
158 | int asn1_enc_save(ASN1_VALUE **pval, const unsigned char *in, int inlen, | 158 | int asn1_enc_save(ASN1_VALUE **pval, const unsigned char *in, int inlen, |
159 | const ASN1_ITEM *it) | 159 | const ASN1_ITEM *it) |
160 | { | 160 | { |
161 | ASN1_ENCODING *enc; | 161 | ASN1_ENCODING *enc; |
162 | enc = asn1_get_enc_ptr(pval, it); | 162 | enc = asn1_get_enc_ptr(pval, it); |
163 | if (!enc) | 163 | if (!enc) |
@@ -173,28 +173,28 @@ int asn1_enc_save(ASN1_VALUE **pval, const unsigned char *in, int inlen, | |||
173 | enc->modified = 0; | 173 | enc->modified = 0; |
174 | 174 | ||
175 | return 1; | 175 | return 1; |
176 | } | 176 | } |
177 | 177 | ||
178 | int asn1_enc_restore(int *len, unsigned char **out, ASN1_VALUE **pval, | 178 | int asn1_enc_restore(int *len, unsigned char **out, ASN1_VALUE **pval, |
179 | const ASN1_ITEM *it) | 179 | const ASN1_ITEM *it) |
180 | { | 180 | { |
181 | ASN1_ENCODING *enc; | 181 | ASN1_ENCODING *enc; |
182 | enc = asn1_get_enc_ptr(pval, it); | 182 | enc = asn1_get_enc_ptr(pval, it); |
183 | if (!enc || enc->modified) | 183 | if (!enc || enc->modified) |
184 | return 0; | 184 | return 0; |
185 | if (out) | 185 | if (out) |
186 | { | 186 | { |
187 | memcpy(*out, enc->enc, enc->len); | 187 | memcpy(*out, enc->enc, enc->len); |
188 | *out += enc->len; | 188 | *out += enc->len; |
189 | } | 189 | } |
190 | if (len) | 190 | if (len) |
191 | *len = enc->len; | 191 | *len = enc->len; |
192 | return 1; | 192 | return 1; |
193 | } | 193 | } |
194 | 194 | ||
195 | /* Given an ASN1_TEMPLATE get a pointer to a field */ | 195 | /* Given an ASN1_TEMPLATE get a pointer to a field */ |
196 | ASN1_VALUE ** asn1_get_field_ptr(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) | 196 | ASN1_VALUE ** asn1_get_field_ptr(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) |
197 | { | 197 | { |
198 | ASN1_VALUE **pvaltmp; | 198 | ASN1_VALUE **pvaltmp; |
199 | if (tt->flags & ASN1_TFLG_COMBINE) | 199 | if (tt->flags & ASN1_TFLG_COMBINE) |
200 | return pval; | 200 | return pval; |
@@ -204,7 +204,7 @@ ASN1_VALUE ** asn1_get_field_ptr(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) | |||
204 | * (int *). | 204 | * (int *). |
205 | */ | 205 | */ |
206 | return pvaltmp; | 206 | return pvaltmp; |
207 | } | 207 | } |
208 | 208 | ||
209 | /* Handle ANY DEFINED BY template, find the selector, look up | 209 | /* Handle ANY DEFINED BY template, find the selector, look up |
210 | * the relevant ASN1_TEMPLATE in the table and return it. | 210 | * the relevant ASN1_TEMPLATE in the table and return it. |
@@ -212,7 +212,7 @@ ASN1_VALUE ** asn1_get_field_ptr(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) | |||
212 | 212 | ||
213 | const ASN1_TEMPLATE *asn1_do_adb(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt, | 213 | const ASN1_TEMPLATE *asn1_do_adb(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt, |
214 | int nullerr) | 214 | int nullerr) |
215 | { | 215 | { |
216 | const ASN1_ADB *adb; | 216 | const ASN1_ADB *adb; |
217 | const ASN1_ADB_TABLE *atbl; | 217 | const ASN1_ADB_TABLE *atbl; |
218 | long selector; | 218 | long selector; |
@@ -229,11 +229,11 @@ const ASN1_TEMPLATE *asn1_do_adb(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt, | |||
229 | 229 | ||
230 | /* Check if NULL */ | 230 | /* Check if NULL */ |
231 | if (!sfld) | 231 | if (!sfld) |
232 | { | 232 | { |
233 | if (!adb->null_tt) | 233 | if (!adb->null_tt) |
234 | goto err; | 234 | goto err; |
235 | return adb->null_tt; | 235 | return adb->null_tt; |
236 | } | 236 | } |
237 | 237 | ||
238 | /* Convert type to a long: | 238 | /* Convert type to a long: |
239 | * NB: don't check for NID_undef here because it | 239 | * NB: don't check for NID_undef here because it |
@@ -269,4 +269,4 @@ const ASN1_TEMPLATE *asn1_do_adb(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt, | |||
269 | ASN1err(ASN1_F_ASN1_DO_ADB, | 269 | ASN1err(ASN1_F_ASN1_DO_ADB, |
270 | ASN1_R_UNSUPPORTED_ANY_DEFINED_BY_TYPE); | 270 | ASN1_R_UNSUPPORTED_ANY_DEFINED_BY_TYPE); |
271 | return NULL; | 271 | return NULL; |
272 | } | 272 | } |
diff --git a/src/lib/libcrypto/asn1/x_algor.c b/src/lib/libcrypto/asn1/x_algor.c index 274e456c73..6f6fbb112a 100644 --- a/src/lib/libcrypto/asn1/x_algor.c +++ b/src/lib/libcrypto/asn1/x_algor.c | |||
@@ -78,60 +78,60 @@ IMPLEMENT_STACK_OF(X509_ALGOR) | |||
78 | IMPLEMENT_ASN1_SET_OF(X509_ALGOR) | 78 | IMPLEMENT_ASN1_SET_OF(X509_ALGOR) |
79 | 79 | ||
80 | int X509_ALGOR_set0(X509_ALGOR *alg, ASN1_OBJECT *aobj, int ptype, void *pval) | 80 | int X509_ALGOR_set0(X509_ALGOR *alg, ASN1_OBJECT *aobj, int ptype, void *pval) |
81 | { | 81 | { |
82 | if (!alg) | 82 | if (!alg) |
83 | return 0; | 83 | return 0; |
84 | if (ptype != V_ASN1_UNDEF) | 84 | if (ptype != V_ASN1_UNDEF) |
85 | { | 85 | { |
86 | if (alg->parameter == NULL) | 86 | if (alg->parameter == NULL) |
87 | alg->parameter = ASN1_TYPE_new(); | 87 | alg->parameter = ASN1_TYPE_new(); |
88 | if (alg->parameter == NULL) | 88 | if (alg->parameter == NULL) |
89 | return 0; | 89 | return 0; |
90 | } | 90 | } |
91 | if (alg) | 91 | if (alg) |
92 | { | 92 | { |
93 | if (alg->algorithm) | 93 | if (alg->algorithm) |
94 | ASN1_OBJECT_free(alg->algorithm); | 94 | ASN1_OBJECT_free(alg->algorithm); |
95 | alg->algorithm = aobj; | 95 | alg->algorithm = aobj; |
96 | } | 96 | } |
97 | if (ptype == 0) | 97 | if (ptype == 0) |
98 | return 1; | 98 | return 1; |
99 | if (ptype == V_ASN1_UNDEF) | 99 | if (ptype == V_ASN1_UNDEF) |
100 | { | 100 | { |
101 | if (alg->parameter) | 101 | if (alg->parameter) |
102 | { | 102 | { |
103 | ASN1_TYPE_free(alg->parameter); | 103 | ASN1_TYPE_free(alg->parameter); |
104 | alg->parameter = NULL; | 104 | alg->parameter = NULL; |
105 | } | ||
106 | } | 105 | } |
106 | } | ||
107 | else | 107 | else |
108 | ASN1_TYPE_set(alg->parameter, ptype, pval); | 108 | ASN1_TYPE_set(alg->parameter, ptype, pval); |
109 | return 1; | 109 | return 1; |
110 | } | 110 | } |
111 | 111 | ||
112 | void X509_ALGOR_get0(ASN1_OBJECT **paobj, int *pptype, void **ppval, | 112 | void X509_ALGOR_get0(ASN1_OBJECT **paobj, int *pptype, void **ppval, |
113 | X509_ALGOR *algor) | 113 | X509_ALGOR *algor) |
114 | { | 114 | { |
115 | if (paobj) | 115 | if (paobj) |
116 | *paobj = algor->algorithm; | 116 | *paobj = algor->algorithm; |
117 | if (pptype) | 117 | if (pptype) |
118 | { | 118 | { |
119 | if (algor->parameter == NULL) | 119 | if (algor->parameter == NULL) |
120 | { | 120 | { |
121 | *pptype = V_ASN1_UNDEF; | 121 | *pptype = V_ASN1_UNDEF; |
122 | return; | 122 | return; |
123 | } | 123 | } |
124 | else | 124 | else |
125 | *pptype = algor->parameter->type; | 125 | *pptype = algor->parameter->type; |
126 | if (ppval) | 126 | if (ppval) |
127 | *ppval = algor->parameter->value.ptr; | 127 | *ppval = algor->parameter->value.ptr; |
128 | } | ||
129 | } | 128 | } |
129 | } | ||
130 | 130 | ||
131 | /* Set up an X509_ALGOR DigestAlgorithmIdentifier from an EVP_MD */ | 131 | /* Set up an X509_ALGOR DigestAlgorithmIdentifier from an EVP_MD */ |
132 | 132 | ||
133 | void X509_ALGOR_set_md(X509_ALGOR *alg, const EVP_MD *md) | 133 | void X509_ALGOR_set_md(X509_ALGOR *alg, const EVP_MD *md) |
134 | { | 134 | { |
135 | int param_type; | 135 | int param_type; |
136 | 136 | ||
137 | if (md->flags & EVP_MD_FLAG_DIGALGID_ABSENT) | 137 | if (md->flags & EVP_MD_FLAG_DIGALGID_ABSENT) |
@@ -141,4 +141,4 @@ void X509_ALGOR_set_md(X509_ALGOR *alg, const EVP_MD *md) | |||
141 | 141 | ||
142 | X509_ALGOR_set0(alg, OBJ_nid2obj(EVP_MD_type(md)), param_type, NULL); | 142 | X509_ALGOR_set0(alg, OBJ_nid2obj(EVP_MD_type(md)), param_type, NULL); |
143 | 143 | ||
144 | } | 144 | } |
diff --git a/src/lib/libcrypto/asn1/x_attrib.c b/src/lib/libcrypto/asn1/x_attrib.c index 1e3713f18f..e620e1224e 100644 --- a/src/lib/libcrypto/asn1/x_attrib.c +++ b/src/lib/libcrypto/asn1/x_attrib.c | |||
@@ -97,7 +97,7 @@ IMPLEMENT_ASN1_FUNCTIONS(X509_ATTRIBUTE) | |||
97 | IMPLEMENT_ASN1_DUP_FUNCTION(X509_ATTRIBUTE) | 97 | IMPLEMENT_ASN1_DUP_FUNCTION(X509_ATTRIBUTE) |
98 | 98 | ||
99 | X509_ATTRIBUTE *X509_ATTRIBUTE_create(int nid, int atrtype, void *value) | 99 | X509_ATTRIBUTE *X509_ATTRIBUTE_create(int nid, int atrtype, void *value) |
100 | { | 100 | { |
101 | X509_ATTRIBUTE *ret=NULL; | 101 | X509_ATTRIBUTE *ret=NULL; |
102 | ASN1_TYPE *val=NULL; | 102 | ASN1_TYPE *val=NULL; |
103 | 103 | ||
@@ -115,4 +115,4 @@ err: | |||
115 | if (ret != NULL) X509_ATTRIBUTE_free(ret); | 115 | if (ret != NULL) X509_ATTRIBUTE_free(ret); |
116 | if (val != NULL) ASN1_TYPE_free(val); | 116 | if (val != NULL) ASN1_TYPE_free(val); |
117 | return(NULL); | 117 | return(NULL); |
118 | } | 118 | } |
diff --git a/src/lib/libcrypto/asn1/x_crl.c b/src/lib/libcrypto/asn1/x_crl.c index cf7e69aaaf..b3a6355795 100644 --- a/src/lib/libcrypto/asn1/x_crl.c +++ b/src/lib/libcrypto/asn1/x_crl.c | |||
@@ -78,12 +78,12 @@ static int def_crl_lookup(X509_CRL *crl, | |||
78 | X509_REVOKED **ret, ASN1_INTEGER *serial, X509_NAME *issuer); | 78 | X509_REVOKED **ret, ASN1_INTEGER *serial, X509_NAME *issuer); |
79 | 79 | ||
80 | static X509_CRL_METHOD int_crl_meth = | 80 | static X509_CRL_METHOD int_crl_meth = |
81 | { | 81 | { |
82 | 0, | 82 | 0, |
83 | 0,0, | 83 | 0,0, |
84 | def_crl_lookup, | 84 | def_crl_lookup, |
85 | def_crl_verify | 85 | def_crl_verify |
86 | }; | 86 | }; |
87 | 87 | ||
88 | static const X509_CRL_METHOD *default_crl_method = &int_crl_meth; | 88 | static const X509_CRL_METHOD *default_crl_method = &int_crl_meth; |
89 | 89 | ||
@@ -104,7 +104,7 @@ static int crl_inf_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, | |||
104 | case ASN1_OP_D2I_POST: | 104 | case ASN1_OP_D2I_POST: |
105 | (void)sk_X509_REVOKED_set_cmp_func(a->revoked,X509_REVOKED_cmp); | 105 | (void)sk_X509_REVOKED_set_cmp_func(a->revoked,X509_REVOKED_cmp); |
106 | break; | 106 | break; |
107 | } | 107 | } |
108 | return 1; | 108 | return 1; |
109 | } | 109 | } |
110 | 110 | ||
@@ -124,7 +124,7 @@ ASN1_SEQUENCE_enc(X509_CRL_INFO, enc, crl_inf_cb) = { | |||
124 | */ | 124 | */ |
125 | 125 | ||
126 | static int crl_set_issuers(X509_CRL *crl) | 126 | static int crl_set_issuers(X509_CRL *crl) |
127 | { | 127 | { |
128 | 128 | ||
129 | int i, j; | 129 | int i, j; |
130 | GENERAL_NAMES *gens, *gtmp; | 130 | GENERAL_NAMES *gens, *gtmp; |
@@ -134,7 +134,7 @@ static int crl_set_issuers(X509_CRL *crl) | |||
134 | 134 | ||
135 | gens = NULL; | 135 | gens = NULL; |
136 | for (i = 0; i < sk_X509_REVOKED_num(revoked); i++) | 136 | for (i = 0; i < sk_X509_REVOKED_num(revoked); i++) |
137 | { | 137 | { |
138 | X509_REVOKED *rev = sk_X509_REVOKED_value(revoked, i); | 138 | X509_REVOKED *rev = sk_X509_REVOKED_value(revoked, i); |
139 | STACK_OF(X509_EXTENSION) *exts; | 139 | STACK_OF(X509_EXTENSION) *exts; |
140 | ASN1_ENUMERATED *reason; | 140 | ASN1_ENUMERATED *reason; |
@@ -143,38 +143,38 @@ static int crl_set_issuers(X509_CRL *crl) | |||
143 | NID_certificate_issuer, | 143 | NID_certificate_issuer, |
144 | &j, NULL); | 144 | &j, NULL); |
145 | if (!gtmp && (j != -1)) | 145 | if (!gtmp && (j != -1)) |
146 | { | 146 | { |
147 | crl->flags |= EXFLAG_INVALID; | 147 | crl->flags |= EXFLAG_INVALID; |
148 | return 1; | 148 | return 1; |
149 | } | 149 | } |
150 | 150 | ||
151 | if (gtmp) | 151 | if (gtmp) |
152 | { | 152 | { |
153 | gens = gtmp; | 153 | gens = gtmp; |
154 | if (!crl->issuers) | 154 | if (!crl->issuers) |
155 | { | 155 | { |
156 | crl->issuers = sk_GENERAL_NAMES_new_null(); | 156 | crl->issuers = sk_GENERAL_NAMES_new_null(); |
157 | if (!crl->issuers) | 157 | if (!crl->issuers) |
158 | return 0; | 158 | return 0; |
159 | } | 159 | } |
160 | if (!sk_GENERAL_NAMES_push(crl->issuers, gtmp)) | 160 | if (!sk_GENERAL_NAMES_push(crl->issuers, gtmp)) |
161 | return 0; | 161 | return 0; |
162 | } | 162 | } |
163 | rev->issuer = gens; | 163 | rev->issuer = gens; |
164 | 164 | ||
165 | reason = X509_REVOKED_get_ext_d2i(rev, NID_crl_reason, | 165 | reason = X509_REVOKED_get_ext_d2i(rev, NID_crl_reason, |
166 | &j, NULL); | 166 | &j, NULL); |
167 | if (!reason && (j != -1)) | 167 | if (!reason && (j != -1)) |
168 | { | 168 | { |
169 | crl->flags |= EXFLAG_INVALID; | 169 | crl->flags |= EXFLAG_INVALID; |
170 | return 1; | 170 | return 1; |
171 | } | 171 | } |
172 | 172 | ||
173 | if (reason) | 173 | if (reason) |
174 | { | 174 | { |
175 | rev->reason = ASN1_ENUMERATED_get(reason); | 175 | rev->reason = ASN1_ENUMERATED_get(reason); |
176 | ASN1_ENUMERATED_free(reason); | 176 | ASN1_ENUMERATED_free(reason); |
177 | } | 177 | } |
178 | else | 178 | else |
179 | rev->reason = CRL_REASON_NONE; | 179 | rev->reason = CRL_REASON_NONE; |
180 | 180 | ||
@@ -183,38 +183,38 @@ static int crl_set_issuers(X509_CRL *crl) | |||
183 | exts = rev->extensions; | 183 | exts = rev->extensions; |
184 | 184 | ||
185 | for (j = 0; j < sk_X509_EXTENSION_num(exts); j++) | 185 | for (j = 0; j < sk_X509_EXTENSION_num(exts); j++) |
186 | { | 186 | { |
187 | ext = sk_X509_EXTENSION_value(exts, j); | 187 | ext = sk_X509_EXTENSION_value(exts, j); |
188 | if (ext->critical > 0) | 188 | if (ext->critical > 0) |
189 | { | 189 | { |
190 | if (OBJ_obj2nid(ext->object) == | 190 | if (OBJ_obj2nid(ext->object) == |
191 | NID_certificate_issuer) | 191 | NID_certificate_issuer) |
192 | continue; | 192 | continue; |
193 | crl->flags |= EXFLAG_CRITICAL; | 193 | crl->flags |= EXFLAG_CRITICAL; |
194 | break; | 194 | break; |
195 | } | ||
196 | } | 195 | } |
196 | } | ||
197 | 197 | ||
198 | 198 | ||
199 | } | 199 | } |
200 | 200 | ||
201 | return 1; | 201 | return 1; |
202 | 202 | ||
203 | } | 203 | } |
204 | 204 | ||
205 | /* The X509_CRL structure needs a bit of customisation. Cache some extensions | 205 | /* The X509_CRL structure needs a bit of customisation. Cache some extensions |
206 | * and hash of the whole CRL. | 206 | * and hash of the whole CRL. |
207 | */ | 207 | */ |
208 | static int crl_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, | 208 | static int crl_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, |
209 | void *exarg) | 209 | void *exarg) |
210 | { | 210 | { |
211 | X509_CRL *crl = (X509_CRL *)*pval; | 211 | X509_CRL *crl = (X509_CRL *)*pval; |
212 | STACK_OF(X509_EXTENSION) *exts; | 212 | STACK_OF(X509_EXTENSION) *exts; |
213 | X509_EXTENSION *ext; | 213 | X509_EXTENSION *ext; |
214 | int idx; | 214 | int idx; |
215 | 215 | ||
216 | switch(operation) | 216 | switch(operation) |
217 | { | 217 | { |
218 | case ASN1_OP_NEW_POST: | 218 | case ASN1_OP_NEW_POST: |
219 | crl->idp = NULL; | 219 | crl->idp = NULL; |
220 | crl->akid = NULL; | 220 | crl->akid = NULL; |
@@ -260,40 +260,40 @@ static int crl_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, | |||
260 | exts = crl->crl->extensions; | 260 | exts = crl->crl->extensions; |
261 | 261 | ||
262 | for (idx = 0; idx < sk_X509_EXTENSION_num(exts); idx++) | 262 | for (idx = 0; idx < sk_X509_EXTENSION_num(exts); idx++) |
263 | { | 263 | { |
264 | int nid; | 264 | int nid; |
265 | ext = sk_X509_EXTENSION_value(exts, idx); | 265 | ext = sk_X509_EXTENSION_value(exts, idx); |
266 | nid = OBJ_obj2nid(ext->object); | 266 | nid = OBJ_obj2nid(ext->object); |
267 | if (nid == NID_freshest_crl) | 267 | if (nid == NID_freshest_crl) |
268 | crl->flags |= EXFLAG_FRESHEST; | 268 | crl->flags |= EXFLAG_FRESHEST; |
269 | if (ext->critical > 0) | 269 | if (ext->critical > 0) |
270 | { | 270 | { |
271 | /* We handle IDP and deltas */ | 271 | /* We handle IDP and deltas */ |
272 | if ((nid == NID_issuing_distribution_point) | 272 | if ((nid == NID_issuing_distribution_point) |
273 | || (nid == NID_delta_crl)) | 273 | || (nid == NID_delta_crl)) |
274 | break;; | 274 | break;; |
275 | crl->flags |= EXFLAG_CRITICAL; | 275 | crl->flags |= EXFLAG_CRITICAL; |
276 | break; | 276 | break; |
277 | } | ||
278 | } | 277 | } |
278 | } | ||
279 | 279 | ||
280 | 280 | ||
281 | if (!crl_set_issuers(crl)) | 281 | if (!crl_set_issuers(crl)) |
282 | return 0; | 282 | return 0; |
283 | 283 | ||
284 | if (crl->meth->crl_init) | 284 | if (crl->meth->crl_init) |
285 | { | 285 | { |
286 | if (crl->meth->crl_init(crl) == 0) | 286 | if (crl->meth->crl_init(crl) == 0) |
287 | return 0; | 287 | return 0; |
288 | } | 288 | } |
289 | break; | 289 | break; |
290 | 290 | ||
291 | case ASN1_OP_FREE_POST: | 291 | case ASN1_OP_FREE_POST: |
292 | if (crl->meth->crl_free) | 292 | if (crl->meth->crl_free) |
293 | { | 293 | { |
294 | if (!crl->meth->crl_free(crl)) | 294 | if (!crl->meth->crl_free(crl)) |
295 | return 0; | 295 | return 0; |
296 | } | 296 | } |
297 | if (crl->akid) | 297 | if (crl->akid) |
298 | AUTHORITY_KEYID_free(crl->akid); | 298 | AUTHORITY_KEYID_free(crl->akid); |
299 | if (crl->idp) | 299 | if (crl->idp) |
@@ -302,32 +302,32 @@ static int crl_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, | |||
302 | ASN1_INTEGER_free(crl->base_crl_number); | 302 | ASN1_INTEGER_free(crl->base_crl_number); |
303 | sk_GENERAL_NAMES_pop_free(crl->issuers, GENERAL_NAMES_free); | 303 | sk_GENERAL_NAMES_pop_free(crl->issuers, GENERAL_NAMES_free); |
304 | break; | 304 | break; |
305 | } | ||
306 | return 1; | ||
307 | } | 305 | } |
306 | return 1; | ||
307 | } | ||
308 | 308 | ||
309 | /* Convert IDP into a more convenient form */ | 309 | /* Convert IDP into a more convenient form */ |
310 | 310 | ||
311 | static void setup_idp(X509_CRL *crl, ISSUING_DIST_POINT *idp) | 311 | static void setup_idp(X509_CRL *crl, ISSUING_DIST_POINT *idp) |
312 | { | 312 | { |
313 | int idp_only = 0; | 313 | int idp_only = 0; |
314 | /* Set various flags according to IDP */ | 314 | /* Set various flags according to IDP */ |
315 | crl->idp_flags |= IDP_PRESENT; | 315 | crl->idp_flags |= IDP_PRESENT; |
316 | if (idp->onlyuser > 0) | 316 | if (idp->onlyuser > 0) |
317 | { | 317 | { |
318 | idp_only++; | 318 | idp_only++; |
319 | crl->idp_flags |= IDP_ONLYUSER; | 319 | crl->idp_flags |= IDP_ONLYUSER; |
320 | } | 320 | } |
321 | if (idp->onlyCA > 0) | 321 | if (idp->onlyCA > 0) |
322 | { | 322 | { |
323 | idp_only++; | 323 | idp_only++; |
324 | crl->idp_flags |= IDP_ONLYCA; | 324 | crl->idp_flags |= IDP_ONLYCA; |
325 | } | 325 | } |
326 | if (idp->onlyattr > 0) | 326 | if (idp->onlyattr > 0) |
327 | { | 327 | { |
328 | idp_only++; | 328 | idp_only++; |
329 | crl->idp_flags |= IDP_ONLYATTR; | 329 | crl->idp_flags |= IDP_ONLYATTR; |
330 | } | 330 | } |
331 | 331 | ||
332 | if (idp_only > 1) | 332 | if (idp_only > 1) |
333 | crl->idp_flags |= IDP_INVALID; | 333 | crl->idp_flags |= IDP_INVALID; |
@@ -336,7 +336,7 @@ static void setup_idp(X509_CRL *crl, ISSUING_DIST_POINT *idp) | |||
336 | crl->idp_flags |= IDP_INDIRECT; | 336 | crl->idp_flags |= IDP_INDIRECT; |
337 | 337 | ||
338 | if (idp->onlysomereasons) | 338 | if (idp->onlysomereasons) |
339 | { | 339 | { |
340 | crl->idp_flags |= IDP_REASONS; | 340 | crl->idp_flags |= IDP_REASONS; |
341 | if (idp->onlysomereasons->length > 0) | 341 | if (idp->onlysomereasons->length > 0) |
342 | crl->idp_reasons = idp->onlysomereasons->data[0]; | 342 | crl->idp_reasons = idp->onlysomereasons->data[0]; |
@@ -344,10 +344,10 @@ static void setup_idp(X509_CRL *crl, ISSUING_DIST_POINT *idp) | |||
344 | crl->idp_reasons |= | 344 | crl->idp_reasons |= |
345 | (idp->onlysomereasons->data[1] << 8); | 345 | (idp->onlysomereasons->data[1] << 8); |
346 | crl->idp_reasons &= CRLDP_ALL_REASONS; | 346 | crl->idp_reasons &= CRLDP_ALL_REASONS; |
347 | } | 347 | } |
348 | 348 | ||
349 | DIST_POINT_set_dpname(idp->distpoint, X509_CRL_get_issuer(crl)); | 349 | DIST_POINT_set_dpname(idp->distpoint, X509_CRL_get_issuer(crl)); |
350 | } | 350 | } |
351 | 351 | ||
352 | ASN1_SEQUENCE_ref(X509_CRL, crl_cb, CRYPTO_LOCK_X509_CRL) = { | 352 | ASN1_SEQUENCE_ref(X509_CRL, crl_cb, CRYPTO_LOCK_X509_CRL) = { |
353 | ASN1_SIMPLE(X509_CRL, crl, X509_CRL_INFO), | 353 | ASN1_SIMPLE(X509_CRL, crl, X509_CRL_INFO), |
@@ -362,11 +362,11 @@ IMPLEMENT_ASN1_DUP_FUNCTION(X509_CRL) | |||
362 | 362 | ||
363 | static int X509_REVOKED_cmp(const X509_REVOKED * const *a, | 363 | static int X509_REVOKED_cmp(const X509_REVOKED * const *a, |
364 | const X509_REVOKED * const *b) | 364 | const X509_REVOKED * const *b) |
365 | { | 365 | { |
366 | return(ASN1_STRING_cmp( | 366 | return(ASN1_STRING_cmp( |
367 | (ASN1_STRING *)(*a)->serialNumber, | 367 | (ASN1_STRING *)(*a)->serialNumber, |
368 | (ASN1_STRING *)(*b)->serialNumber)); | 368 | (ASN1_STRING *)(*b)->serialNumber)); |
369 | } | 369 | } |
370 | 370 | ||
371 | int X509_CRL_add0_revoked(X509_CRL *crl, X509_REVOKED *rev) | 371 | int X509_CRL_add0_revoked(X509_CRL *crl, X509_REVOKED *rev) |
372 | { | 372 | { |
@@ -377,73 +377,73 @@ int X509_CRL_add0_revoked(X509_CRL *crl, X509_REVOKED *rev) | |||
377 | if(!inf->revoked || !sk_X509_REVOKED_push(inf->revoked, rev)) { | 377 | if(!inf->revoked || !sk_X509_REVOKED_push(inf->revoked, rev)) { |
378 | ASN1err(ASN1_F_X509_CRL_ADD0_REVOKED, ERR_R_MALLOC_FAILURE); | 378 | ASN1err(ASN1_F_X509_CRL_ADD0_REVOKED, ERR_R_MALLOC_FAILURE); |
379 | return 0; | 379 | return 0; |
380 | } | 380 | } |
381 | inf->enc.modified = 1; | 381 | inf->enc.modified = 1; |
382 | return 1; | 382 | return 1; |
383 | } | 383 | } |
384 | 384 | ||
385 | int X509_CRL_verify(X509_CRL *crl, EVP_PKEY *r) | 385 | int X509_CRL_verify(X509_CRL *crl, EVP_PKEY *r) |
386 | { | 386 | { |
387 | if (crl->meth->crl_verify) | 387 | if (crl->meth->crl_verify) |
388 | return crl->meth->crl_verify(crl, r); | 388 | return crl->meth->crl_verify(crl, r); |
389 | return 0; | 389 | return 0; |
390 | } | 390 | } |
391 | 391 | ||
392 | int X509_CRL_get0_by_serial(X509_CRL *crl, | 392 | int X509_CRL_get0_by_serial(X509_CRL *crl, |
393 | X509_REVOKED **ret, ASN1_INTEGER *serial) | 393 | X509_REVOKED **ret, ASN1_INTEGER *serial) |
394 | { | 394 | { |
395 | if (crl->meth->crl_lookup) | 395 | if (crl->meth->crl_lookup) |
396 | return crl->meth->crl_lookup(crl, ret, serial, NULL); | 396 | return crl->meth->crl_lookup(crl, ret, serial, NULL); |
397 | return 0; | 397 | return 0; |
398 | } | 398 | } |
399 | 399 | ||
400 | int X509_CRL_get0_by_cert(X509_CRL *crl, X509_REVOKED **ret, X509 *x) | 400 | int X509_CRL_get0_by_cert(X509_CRL *crl, X509_REVOKED **ret, X509 *x) |
401 | { | 401 | { |
402 | if (crl->meth->crl_lookup) | 402 | if (crl->meth->crl_lookup) |
403 | return crl->meth->crl_lookup(crl, ret, | 403 | return crl->meth->crl_lookup(crl, ret, |
404 | X509_get_serialNumber(x), | 404 | X509_get_serialNumber(x), |
405 | X509_get_issuer_name(x)); | 405 | X509_get_issuer_name(x)); |
406 | return 0; | 406 | return 0; |
407 | } | 407 | } |
408 | 408 | ||
409 | static int def_crl_verify(X509_CRL *crl, EVP_PKEY *r) | 409 | static int def_crl_verify(X509_CRL *crl, EVP_PKEY *r) |
410 | { | 410 | { |
411 | return(ASN1_item_verify(ASN1_ITEM_rptr(X509_CRL_INFO), | 411 | return(ASN1_item_verify(ASN1_ITEM_rptr(X509_CRL_INFO), |
412 | crl->sig_alg, crl->signature,crl->crl,r)); | 412 | crl->sig_alg, crl->signature,crl->crl,r)); |
413 | } | 413 | } |
414 | 414 | ||
415 | static int crl_revoked_issuer_match(X509_CRL *crl, X509_NAME *nm, | 415 | static int crl_revoked_issuer_match(X509_CRL *crl, X509_NAME *nm, |
416 | X509_REVOKED *rev) | 416 | X509_REVOKED *rev) |
417 | { | 417 | { |
418 | int i; | 418 | int i; |
419 | 419 | ||
420 | if (!rev->issuer) | 420 | if (!rev->issuer) |
421 | { | 421 | { |
422 | if (!nm) | 422 | if (!nm) |
423 | return 1; | 423 | return 1; |
424 | if (!X509_NAME_cmp(nm, X509_CRL_get_issuer(crl))) | 424 | if (!X509_NAME_cmp(nm, X509_CRL_get_issuer(crl))) |
425 | return 1; | 425 | return 1; |
426 | return 0; | 426 | return 0; |
427 | } | 427 | } |
428 | 428 | ||
429 | if (!nm) | 429 | if (!nm) |
430 | nm = X509_CRL_get_issuer(crl); | 430 | nm = X509_CRL_get_issuer(crl); |
431 | 431 | ||
432 | for (i = 0; i < sk_GENERAL_NAME_num(rev->issuer); i++) | 432 | for (i = 0; i < sk_GENERAL_NAME_num(rev->issuer); i++) |
433 | { | 433 | { |
434 | GENERAL_NAME *gen = sk_GENERAL_NAME_value(rev->issuer, i); | 434 | GENERAL_NAME *gen = sk_GENERAL_NAME_value(rev->issuer, i); |
435 | if (gen->type != GEN_DIRNAME) | 435 | if (gen->type != GEN_DIRNAME) |
436 | continue; | 436 | continue; |
437 | if (!X509_NAME_cmp(nm, gen->d.directoryName)) | 437 | if (!X509_NAME_cmp(nm, gen->d.directoryName)) |
438 | return 1; | 438 | return 1; |
439 | } | 439 | } |
440 | return 0; | 440 | return 0; |
441 | 441 | ||
442 | } | 442 | } |
443 | 443 | ||
444 | static int def_crl_lookup(X509_CRL *crl, | 444 | static int def_crl_lookup(X509_CRL *crl, |
445 | X509_REVOKED **ret, ASN1_INTEGER *serial, X509_NAME *issuer) | 445 | X509_REVOKED **ret, ASN1_INTEGER *serial, X509_NAME *issuer) |
446 | { | 446 | { |
447 | X509_REVOKED rtmp, *rev; | 447 | X509_REVOKED rtmp, *rev; |
448 | int idx; | 448 | int idx; |
449 | rtmp.serialNumber = serial; | 449 | rtmp.serialNumber = serial; |
@@ -451,39 +451,39 @@ static int def_crl_lookup(X509_CRL *crl, | |||
451 | * Do this under a lock to avoid race condition. | 451 | * Do this under a lock to avoid race condition. |
452 | */ | 452 | */ |
453 | if (!sk_X509_REVOKED_is_sorted(crl->crl->revoked)) | 453 | if (!sk_X509_REVOKED_is_sorted(crl->crl->revoked)) |
454 | { | 454 | { |
455 | CRYPTO_w_lock(CRYPTO_LOCK_X509_CRL); | 455 | CRYPTO_w_lock(CRYPTO_LOCK_X509_CRL); |
456 | sk_X509_REVOKED_sort(crl->crl->revoked); | 456 | sk_X509_REVOKED_sort(crl->crl->revoked); |
457 | CRYPTO_w_unlock(CRYPTO_LOCK_X509_CRL); | 457 | CRYPTO_w_unlock(CRYPTO_LOCK_X509_CRL); |
458 | } | 458 | } |
459 | idx = sk_X509_REVOKED_find(crl->crl->revoked, &rtmp); | 459 | idx = sk_X509_REVOKED_find(crl->crl->revoked, &rtmp); |
460 | if(idx < 0) | 460 | if(idx < 0) |
461 | return 0; | 461 | return 0; |
462 | /* Need to look for matching name */ | 462 | /* Need to look for matching name */ |
463 | for(;idx < sk_X509_REVOKED_num(crl->crl->revoked); idx++) | 463 | for(;idx < sk_X509_REVOKED_num(crl->crl->revoked); idx++) |
464 | { | 464 | { |
465 | rev = sk_X509_REVOKED_value(crl->crl->revoked, idx); | 465 | rev = sk_X509_REVOKED_value(crl->crl->revoked, idx); |
466 | if (ASN1_INTEGER_cmp(rev->serialNumber, serial)) | 466 | if (ASN1_INTEGER_cmp(rev->serialNumber, serial)) |
467 | return 0; | 467 | return 0; |
468 | if (crl_revoked_issuer_match(crl, issuer, rev)) | 468 | if (crl_revoked_issuer_match(crl, issuer, rev)) |
469 | { | 469 | { |
470 | if (ret) | 470 | if (ret) |
471 | *ret = rev; | 471 | *ret = rev; |
472 | if (rev->reason == CRL_REASON_REMOVE_FROM_CRL) | 472 | if (rev->reason == CRL_REASON_REMOVE_FROM_CRL) |
473 | return 2; | 473 | return 2; |
474 | return 1; | 474 | return 1; |
475 | } | ||
476 | } | 475 | } |
477 | return 0; | ||
478 | } | 476 | } |
477 | return 0; | ||
478 | } | ||
479 | 479 | ||
480 | void X509_CRL_set_default_method(const X509_CRL_METHOD *meth) | 480 | void X509_CRL_set_default_method(const X509_CRL_METHOD *meth) |
481 | { | 481 | { |
482 | if (meth == NULL) | 482 | if (meth == NULL) |
483 | default_crl_method = &int_crl_meth; | 483 | default_crl_method = &int_crl_meth; |
484 | else | 484 | else |
485 | default_crl_method = meth; | 485 | default_crl_method = meth; |
486 | } | 486 | } |
487 | 487 | ||
488 | X509_CRL_METHOD *X509_CRL_METHOD_new( | 488 | X509_CRL_METHOD *X509_CRL_METHOD_new( |
489 | int (*crl_init)(X509_CRL *crl), | 489 | int (*crl_init)(X509_CRL *crl), |
@@ -491,7 +491,7 @@ X509_CRL_METHOD *X509_CRL_METHOD_new( | |||
491 | int (*crl_lookup)(X509_CRL *crl, X509_REVOKED **ret, | 491 | int (*crl_lookup)(X509_CRL *crl, X509_REVOKED **ret, |
492 | ASN1_INTEGER *ser, X509_NAME *issuer), | 492 | ASN1_INTEGER *ser, X509_NAME *issuer), |
493 | int (*crl_verify)(X509_CRL *crl, EVP_PKEY *pk)) | 493 | int (*crl_verify)(X509_CRL *crl, EVP_PKEY *pk)) |
494 | { | 494 | { |
495 | X509_CRL_METHOD *m; | 495 | X509_CRL_METHOD *m; |
496 | m = malloc(sizeof(X509_CRL_METHOD)); | 496 | m = malloc(sizeof(X509_CRL_METHOD)); |
497 | if (!m) | 497 | if (!m) |
@@ -502,24 +502,24 @@ X509_CRL_METHOD *X509_CRL_METHOD_new( | |||
502 | m->crl_verify = crl_verify; | 502 | m->crl_verify = crl_verify; |
503 | m->flags = X509_CRL_METHOD_DYNAMIC; | 503 | m->flags = X509_CRL_METHOD_DYNAMIC; |
504 | return m; | 504 | return m; |
505 | } | 505 | } |
506 | 506 | ||
507 | void X509_CRL_METHOD_free(X509_CRL_METHOD *m) | 507 | void X509_CRL_METHOD_free(X509_CRL_METHOD *m) |
508 | { | 508 | { |
509 | if (!(m->flags & X509_CRL_METHOD_DYNAMIC)) | 509 | if (!(m->flags & X509_CRL_METHOD_DYNAMIC)) |
510 | return; | 510 | return; |
511 | free(m); | 511 | free(m); |
512 | } | 512 | } |
513 | 513 | ||
514 | void X509_CRL_set_meth_data(X509_CRL *crl, void *dat) | 514 | void X509_CRL_set_meth_data(X509_CRL *crl, void *dat) |
515 | { | 515 | { |
516 | crl->meth_data = dat; | 516 | crl->meth_data = dat; |
517 | } | 517 | } |
518 | 518 | ||
519 | void *X509_CRL_get_meth_data(X509_CRL *crl) | 519 | void *X509_CRL_get_meth_data(X509_CRL *crl) |
520 | { | 520 | { |
521 | return crl->meth_data; | 521 | return crl->meth_data; |
522 | } | 522 | } |
523 | 523 | ||
524 | IMPLEMENT_STACK_OF(X509_REVOKED) | 524 | IMPLEMENT_STACK_OF(X509_REVOKED) |
525 | IMPLEMENT_ASN1_SET_OF(X509_REVOKED) | 525 | IMPLEMENT_ASN1_SET_OF(X509_REVOKED) |
diff --git a/src/lib/libcrypto/asn1/x_info.c b/src/lib/libcrypto/asn1/x_info.c index cb5b6634a1..c1b6058d58 100644 --- a/src/lib/libcrypto/asn1/x_info.c +++ b/src/lib/libcrypto/asn1/x_info.c | |||
@@ -63,15 +63,15 @@ | |||
63 | #include <openssl/x509.h> | 63 | #include <openssl/x509.h> |
64 | 64 | ||
65 | X509_INFO *X509_INFO_new(void) | 65 | X509_INFO *X509_INFO_new(void) |
66 | { | 66 | { |
67 | X509_INFO *ret=NULL; | 67 | X509_INFO *ret=NULL; |
68 | 68 | ||
69 | ret=(X509_INFO *)malloc(sizeof(X509_INFO)); | 69 | ret=(X509_INFO *)malloc(sizeof(X509_INFO)); |
70 | if (ret == NULL) | 70 | if (ret == NULL) |
71 | { | 71 | { |
72 | ASN1err(ASN1_F_X509_INFO_NEW,ERR_R_MALLOC_FAILURE); | 72 | ASN1err(ASN1_F_X509_INFO_NEW,ERR_R_MALLOC_FAILURE); |
73 | return(NULL); | 73 | return(NULL); |
74 | } | 74 | } |
75 | 75 | ||
76 | ret->enc_cipher.cipher=NULL; | 76 | ret->enc_cipher.cipher=NULL; |
77 | ret->enc_len=0; | 77 | ret->enc_len=0; |
@@ -82,10 +82,10 @@ X509_INFO *X509_INFO_new(void) | |||
82 | ret->crl=NULL; | 82 | ret->crl=NULL; |
83 | ret->x_pkey=NULL; | 83 | ret->x_pkey=NULL; |
84 | return(ret); | 84 | return(ret); |
85 | } | 85 | } |
86 | 86 | ||
87 | void X509_INFO_free(X509_INFO *x) | 87 | void X509_INFO_free(X509_INFO *x) |
88 | { | 88 | { |
89 | int i; | 89 | int i; |
90 | 90 | ||
91 | if (x == NULL) return; | 91 | if (x == NULL) return; |
@@ -98,7 +98,7 @@ void X509_INFO_free(X509_INFO *x) | |||
98 | if (x->x_pkey != NULL) X509_PKEY_free(x->x_pkey); | 98 | if (x->x_pkey != NULL) X509_PKEY_free(x->x_pkey); |
99 | if (x->enc_data != NULL) free(x->enc_data); | 99 | if (x->enc_data != NULL) free(x->enc_data); |
100 | free(x); | 100 | free(x); |
101 | } | 101 | } |
102 | 102 | ||
103 | IMPLEMENT_STACK_OF(X509_INFO) | 103 | IMPLEMENT_STACK_OF(X509_INFO) |
104 | 104 | ||
diff --git a/src/lib/libcrypto/asn1/x_long.c b/src/lib/libcrypto/asn1/x_long.c index 75317418e1..1417284d3c 100644 --- a/src/lib/libcrypto/asn1/x_long.c +++ b/src/lib/libcrypto/asn1/x_long.c | |||
@@ -174,6 +174,6 @@ static int long_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, | |||
174 | 174 | ||
175 | static int long_print(BIO *out, ASN1_VALUE **pval, const ASN1_ITEM *it, | 175 | static int long_print(BIO *out, ASN1_VALUE **pval, const ASN1_ITEM *it, |
176 | int indent, const ASN1_PCTX *pctx) | 176 | int indent, const ASN1_PCTX *pctx) |
177 | { | 177 | { |
178 | return BIO_printf(out, "%ld\n", *(long *)pval); | 178 | return BIO_printf(out, "%ld\n", *(long *)pval); |
179 | } | 179 | } |
diff --git a/src/lib/libcrypto/asn1/x_name.c b/src/lib/libcrypto/asn1/x_name.c index e14d329639..dfd4363aa0 100644 --- a/src/lib/libcrypto/asn1/x_name.c +++ b/src/lib/libcrypto/asn1/x_name.c | |||
@@ -146,11 +146,11 @@ static int x509_name_ex_new(ASN1_VALUE **val, const ASN1_ITEM *it) | |||
146 | memerr: | 146 | memerr: |
147 | ASN1err(ASN1_F_X509_NAME_EX_NEW, ERR_R_MALLOC_FAILURE); | 147 | ASN1err(ASN1_F_X509_NAME_EX_NEW, ERR_R_MALLOC_FAILURE); |
148 | if (ret) | 148 | if (ret) |
149 | { | 149 | { |
150 | if (ret->entries) | 150 | if (ret->entries) |
151 | sk_X509_NAME_ENTRY_free(ret->entries); | 151 | sk_X509_NAME_ENTRY_free(ret->entries); |
152 | free(ret); | 152 | free(ret); |
153 | } | 153 | } |
154 | return 0; | 154 | return 0; |
155 | } | 155 | } |
156 | 156 | ||
diff --git a/src/lib/libcrypto/asn1/x_pkey.c b/src/lib/libcrypto/asn1/x_pkey.c index c37f207e33..37d2d93968 100644 --- a/src/lib/libcrypto/asn1/x_pkey.c +++ b/src/lib/libcrypto/asn1/x_pkey.c | |||
@@ -65,12 +65,12 @@ | |||
65 | 65 | ||
66 | /* need to implement */ | 66 | /* need to implement */ |
67 | int i2d_X509_PKEY(X509_PKEY *a, unsigned char **pp) | 67 | int i2d_X509_PKEY(X509_PKEY *a, unsigned char **pp) |
68 | { | 68 | { |
69 | return(0); | 69 | return(0); |
70 | } | 70 | } |
71 | 71 | ||
72 | X509_PKEY *d2i_X509_PKEY(X509_PKEY **a, const unsigned char **pp, long length) | 72 | X509_PKEY *d2i_X509_PKEY(X509_PKEY **a, const unsigned char **pp, long length) |
73 | { | 73 | { |
74 | int i; | 74 | int i; |
75 | M_ASN1_D2I_vars(a,X509_PKEY *,X509_PKEY_new); | 75 | M_ASN1_D2I_vars(a,X509_PKEY *,X509_PKEY_new); |
76 | 76 | ||
@@ -82,30 +82,30 @@ X509_PKEY *d2i_X509_PKEY(X509_PKEY **a, const unsigned char **pp, long length) | |||
82 | ret->cipher.cipher=EVP_get_cipherbyname( | 82 | ret->cipher.cipher=EVP_get_cipherbyname( |
83 | OBJ_nid2ln(OBJ_obj2nid(ret->enc_algor->algorithm))); | 83 | OBJ_nid2ln(OBJ_obj2nid(ret->enc_algor->algorithm))); |
84 | if (ret->cipher.cipher == NULL) | 84 | if (ret->cipher.cipher == NULL) |
85 | { | 85 | { |
86 | c.error=ASN1_R_UNSUPPORTED_CIPHER; | 86 | c.error=ASN1_R_UNSUPPORTED_CIPHER; |
87 | c.line=__LINE__; | 87 | c.line=__LINE__; |
88 | goto err; | 88 | goto err; |
89 | } | 89 | } |
90 | if (ret->enc_algor->parameter->type == V_ASN1_OCTET_STRING) | 90 | if (ret->enc_algor->parameter->type == V_ASN1_OCTET_STRING) |
91 | { | 91 | { |
92 | i=ret->enc_algor->parameter->value.octet_string->length; | 92 | i=ret->enc_algor->parameter->value.octet_string->length; |
93 | if (i > EVP_MAX_IV_LENGTH) | 93 | if (i > EVP_MAX_IV_LENGTH) |
94 | { | 94 | { |
95 | c.error=ASN1_R_IV_TOO_LARGE; | 95 | c.error=ASN1_R_IV_TOO_LARGE; |
96 | c.line=__LINE__; | 96 | c.line=__LINE__; |
97 | goto err; | 97 | goto err; |
98 | } | 98 | } |
99 | memcpy(ret->cipher.iv, | 99 | memcpy(ret->cipher.iv, |
100 | ret->enc_algor->parameter->value.octet_string->data,i); | 100 | ret->enc_algor->parameter->value.octet_string->data,i); |
101 | } | 101 | } |
102 | else | 102 | else |
103 | memset(ret->cipher.iv,0,EVP_MAX_IV_LENGTH); | 103 | memset(ret->cipher.iv,0,EVP_MAX_IV_LENGTH); |
104 | M_ASN1_D2I_Finish(a,X509_PKEY_free,ASN1_F_D2I_X509_PKEY); | 104 | M_ASN1_D2I_Finish(a,X509_PKEY_free,ASN1_F_D2I_X509_PKEY); |
105 | } | 105 | } |
106 | 106 | ||
107 | X509_PKEY *X509_PKEY_new(void) | 107 | X509_PKEY *X509_PKEY_new(void) |
108 | { | 108 | { |
109 | X509_PKEY *ret=NULL; | 109 | X509_PKEY *ret=NULL; |
110 | ASN1_CTX c; | 110 | ASN1_CTX c; |
111 | 111 | ||
@@ -122,10 +122,10 @@ X509_PKEY *X509_PKEY_new(void) | |||
122 | ret->references=1; | 122 | ret->references=1; |
123 | return(ret); | 123 | return(ret); |
124 | M_ASN1_New_Error(ASN1_F_X509_PKEY_NEW); | 124 | M_ASN1_New_Error(ASN1_F_X509_PKEY_NEW); |
125 | } | 125 | } |
126 | 126 | ||
127 | void X509_PKEY_free(X509_PKEY *x) | 127 | void X509_PKEY_free(X509_PKEY *x) |
128 | { | 128 | { |
129 | int i; | 129 | int i; |
130 | 130 | ||
131 | if (x == NULL) return; | 131 | if (x == NULL) return; |
@@ -138,4 +138,4 @@ void X509_PKEY_free(X509_PKEY *x) | |||
138 | if (x->dec_pkey != NULL)EVP_PKEY_free(x->dec_pkey); | 138 | if (x->dec_pkey != NULL)EVP_PKEY_free(x->dec_pkey); |
139 | if ((x->key_data != NULL) && (x->key_free)) free(x->key_data); | 139 | if ((x->key_data != NULL) && (x->key_free)) free(x->key_data); |
140 | free(x); | 140 | free(x); |
141 | } | 141 | } |
diff --git a/src/lib/libcrypto/asn1/x_pubkey.c b/src/lib/libcrypto/asn1/x_pubkey.c index 684f40899f..454d50f24c 100644 --- a/src/lib/libcrypto/asn1/x_pubkey.c +++ b/src/lib/libcrypto/asn1/x_pubkey.c | |||
@@ -71,14 +71,14 @@ | |||
71 | /* Minor tweak to operation: free up EVP_PKEY */ | 71 | /* Minor tweak to operation: free up EVP_PKEY */ |
72 | static int pubkey_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, | 72 | static int pubkey_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, |
73 | void *exarg) | 73 | void *exarg) |
74 | { | 74 | { |
75 | if (operation == ASN1_OP_FREE_POST) | 75 | if (operation == ASN1_OP_FREE_POST) |
76 | { | 76 | { |
77 | X509_PUBKEY *pubkey = (X509_PUBKEY *)*pval; | 77 | X509_PUBKEY *pubkey = (X509_PUBKEY *)*pval; |
78 | EVP_PKEY_free(pubkey->pkey); | 78 | EVP_PKEY_free(pubkey->pkey); |
79 | } | ||
80 | return 1; | ||
81 | } | 79 | } |
80 | return 1; | ||
81 | } | ||
82 | 82 | ||
83 | ASN1_SEQUENCE_cb(X509_PUBKEY, pubkey_cb) = { | 83 | ASN1_SEQUENCE_cb(X509_PUBKEY, pubkey_cb) = { |
84 | ASN1_SIMPLE(X509_PUBKEY, algor, X509_ALGOR), | 84 | ASN1_SIMPLE(X509_PUBKEY, algor, X509_ALGOR), |
@@ -88,7 +88,7 @@ ASN1_SEQUENCE_cb(X509_PUBKEY, pubkey_cb) = { | |||
88 | IMPLEMENT_ASN1_FUNCTIONS(X509_PUBKEY) | 88 | IMPLEMENT_ASN1_FUNCTIONS(X509_PUBKEY) |
89 | 89 | ||
90 | int X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey) | 90 | int X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey) |
91 | { | 91 | { |
92 | X509_PUBKEY *pk=NULL; | 92 | X509_PUBKEY *pk=NULL; |
93 | 93 | ||
94 | if (x == NULL) return(0); | 94 | if (x == NULL) return(0); |
@@ -96,28 +96,28 @@ int X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey) | |||
96 | if ((pk=X509_PUBKEY_new()) == NULL) goto error; | 96 | if ((pk=X509_PUBKEY_new()) == NULL) goto error; |
97 | 97 | ||
98 | if (pkey->ameth) | 98 | if (pkey->ameth) |
99 | { | 99 | { |
100 | if (pkey->ameth->pub_encode) | 100 | if (pkey->ameth->pub_encode) |
101 | { | 101 | { |
102 | if (!pkey->ameth->pub_encode(pk, pkey)) | 102 | if (!pkey->ameth->pub_encode(pk, pkey)) |
103 | { | 103 | { |
104 | X509err(X509_F_X509_PUBKEY_SET, | 104 | X509err(X509_F_X509_PUBKEY_SET, |
105 | X509_R_PUBLIC_KEY_ENCODE_ERROR); | 105 | X509_R_PUBLIC_KEY_ENCODE_ERROR); |
106 | goto error; | 106 | goto error; |
107 | } | ||
108 | } | 107 | } |
108 | } | ||
109 | else | 109 | else |
110 | { | 110 | { |
111 | X509err(X509_F_X509_PUBKEY_SET, | 111 | X509err(X509_F_X509_PUBKEY_SET, |
112 | X509_R_METHOD_NOT_SUPPORTED); | 112 | X509_R_METHOD_NOT_SUPPORTED); |
113 | goto error; | 113 | goto error; |
114 | } | ||
115 | } | 114 | } |
115 | } | ||
116 | else | 116 | else |
117 | { | 117 | { |
118 | X509err(X509_F_X509_PUBKEY_SET,X509_R_UNSUPPORTED_ALGORITHM); | 118 | X509err(X509_F_X509_PUBKEY_SET,X509_R_UNSUPPORTED_ALGORITHM); |
119 | goto error; | 119 | goto error; |
120 | } | 120 | } |
121 | 121 | ||
122 | if (*x != NULL) | 122 | if (*x != NULL) |
123 | X509_PUBKEY_free(*x); | 123 | X509_PUBKEY_free(*x); |
@@ -128,62 +128,62 @@ int X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey) | |||
128 | error: | 128 | error: |
129 | if (pk != NULL) X509_PUBKEY_free(pk); | 129 | if (pk != NULL) X509_PUBKEY_free(pk); |
130 | return 0; | 130 | return 0; |
131 | } | 131 | } |
132 | 132 | ||
133 | EVP_PKEY *X509_PUBKEY_get(X509_PUBKEY *key) | 133 | EVP_PKEY *X509_PUBKEY_get(X509_PUBKEY *key) |
134 | { | 134 | { |
135 | EVP_PKEY *ret=NULL; | 135 | EVP_PKEY *ret=NULL; |
136 | 136 | ||
137 | if (key == NULL) goto error; | 137 | if (key == NULL) goto error; |
138 | 138 | ||
139 | if (key->pkey != NULL) | 139 | if (key->pkey != NULL) |
140 | { | 140 | { |
141 | CRYPTO_add(&key->pkey->references, 1, CRYPTO_LOCK_EVP_PKEY); | 141 | CRYPTO_add(&key->pkey->references, 1, CRYPTO_LOCK_EVP_PKEY); |
142 | return key->pkey; | 142 | return key->pkey; |
143 | } | 143 | } |
144 | 144 | ||
145 | if (key->public_key == NULL) goto error; | 145 | if (key->public_key == NULL) goto error; |
146 | 146 | ||
147 | if ((ret = EVP_PKEY_new()) == NULL) | 147 | if ((ret = EVP_PKEY_new()) == NULL) |
148 | { | 148 | { |
149 | X509err(X509_F_X509_PUBKEY_GET, ERR_R_MALLOC_FAILURE); | 149 | X509err(X509_F_X509_PUBKEY_GET, ERR_R_MALLOC_FAILURE); |
150 | goto error; | 150 | goto error; |
151 | } | 151 | } |
152 | 152 | ||
153 | if (!EVP_PKEY_set_type(ret, OBJ_obj2nid(key->algor->algorithm))) | 153 | if (!EVP_PKEY_set_type(ret, OBJ_obj2nid(key->algor->algorithm))) |
154 | { | 154 | { |
155 | X509err(X509_F_X509_PUBKEY_GET,X509_R_UNSUPPORTED_ALGORITHM); | 155 | X509err(X509_F_X509_PUBKEY_GET,X509_R_UNSUPPORTED_ALGORITHM); |
156 | goto error; | 156 | goto error; |
157 | } | 157 | } |
158 | 158 | ||
159 | if (ret->ameth->pub_decode) | 159 | if (ret->ameth->pub_decode) |
160 | { | 160 | { |
161 | if (!ret->ameth->pub_decode(ret, key)) | 161 | if (!ret->ameth->pub_decode(ret, key)) |
162 | { | 162 | { |
163 | X509err(X509_F_X509_PUBKEY_GET, | 163 | X509err(X509_F_X509_PUBKEY_GET, |
164 | X509_R_PUBLIC_KEY_DECODE_ERROR); | 164 | X509_R_PUBLIC_KEY_DECODE_ERROR); |
165 | goto error; | 165 | goto error; |
166 | } | ||
167 | } | 166 | } |
167 | } | ||
168 | else | 168 | else |
169 | { | 169 | { |
170 | X509err(X509_F_X509_PUBKEY_GET, X509_R_METHOD_NOT_SUPPORTED); | 170 | X509err(X509_F_X509_PUBKEY_GET, X509_R_METHOD_NOT_SUPPORTED); |
171 | goto error; | 171 | goto error; |
172 | } | 172 | } |
173 | 173 | ||
174 | /* Check to see if another thread set key->pkey first */ | 174 | /* Check to see if another thread set key->pkey first */ |
175 | CRYPTO_w_lock(CRYPTO_LOCK_EVP_PKEY); | 175 | CRYPTO_w_lock(CRYPTO_LOCK_EVP_PKEY); |
176 | if (key->pkey) | 176 | if (key->pkey) |
177 | { | 177 | { |
178 | CRYPTO_w_unlock(CRYPTO_LOCK_EVP_PKEY); | 178 | CRYPTO_w_unlock(CRYPTO_LOCK_EVP_PKEY); |
179 | EVP_PKEY_free(ret); | 179 | EVP_PKEY_free(ret); |
180 | ret = key->pkey; | 180 | ret = key->pkey; |
181 | } | 181 | } |
182 | else | 182 | else |
183 | { | 183 | { |
184 | key->pkey = ret; | 184 | key->pkey = ret; |
185 | CRYPTO_w_unlock(CRYPTO_LOCK_EVP_PKEY); | 185 | CRYPTO_w_unlock(CRYPTO_LOCK_EVP_PKEY); |
186 | } | 186 | } |
187 | CRYPTO_add(&ret->references, 1, CRYPTO_LOCK_EVP_PKEY); | 187 | CRYPTO_add(&ret->references, 1, CRYPTO_LOCK_EVP_PKEY); |
188 | 188 | ||
189 | return ret; | 189 | return ret; |
@@ -192,7 +192,7 @@ EVP_PKEY *X509_PUBKEY_get(X509_PUBKEY *key) | |||
192 | if (ret != NULL) | 192 | if (ret != NULL) |
193 | EVP_PKEY_free(ret); | 193 | EVP_PKEY_free(ret); |
194 | return(NULL); | 194 | return(NULL); |
195 | } | 195 | } |
196 | 196 | ||
197 | /* Now two pseudo ASN1 routines that take an EVP_PKEY structure | 197 | /* Now two pseudo ASN1 routines that take an EVP_PKEY structure |
198 | * and encode or decode as X509_PUBKEY | 198 | * and encode or decode as X509_PUBKEY |
@@ -200,7 +200,7 @@ EVP_PKEY *X509_PUBKEY_get(X509_PUBKEY *key) | |||
200 | 200 | ||
201 | EVP_PKEY *d2i_PUBKEY(EVP_PKEY **a, const unsigned char **pp, | 201 | EVP_PKEY *d2i_PUBKEY(EVP_PKEY **a, const unsigned char **pp, |
202 | long length) | 202 | long length) |
203 | { | 203 | { |
204 | X509_PUBKEY *xpk; | 204 | X509_PUBKEY *xpk; |
205 | EVP_PKEY *pktmp; | 205 | EVP_PKEY *pktmp; |
206 | xpk = d2i_X509_PUBKEY(NULL, pp, length); | 206 | xpk = d2i_X509_PUBKEY(NULL, pp, length); |
@@ -209,15 +209,15 @@ EVP_PKEY *d2i_PUBKEY(EVP_PKEY **a, const unsigned char **pp, | |||
209 | X509_PUBKEY_free(xpk); | 209 | X509_PUBKEY_free(xpk); |
210 | if(!pktmp) return NULL; | 210 | if(!pktmp) return NULL; |
211 | if(a) | 211 | if(a) |
212 | { | 212 | { |
213 | EVP_PKEY_free(*a); | 213 | EVP_PKEY_free(*a); |
214 | *a = pktmp; | 214 | *a = pktmp; |
215 | } | ||
216 | return pktmp; | ||
217 | } | 215 | } |
216 | return pktmp; | ||
217 | } | ||
218 | 218 | ||
219 | int i2d_PUBKEY(EVP_PKEY *a, unsigned char **pp) | 219 | int i2d_PUBKEY(EVP_PKEY *a, unsigned char **pp) |
220 | { | 220 | { |
221 | X509_PUBKEY *xpk=NULL; | 221 | X509_PUBKEY *xpk=NULL; |
222 | int ret; | 222 | int ret; |
223 | if(!a) return 0; | 223 | if(!a) return 0; |
@@ -225,7 +225,7 @@ int i2d_PUBKEY(EVP_PKEY *a, unsigned char **pp) | |||
225 | ret = i2d_X509_PUBKEY(xpk, pp); | 225 | ret = i2d_X509_PUBKEY(xpk, pp); |
226 | X509_PUBKEY_free(xpk); | 226 | X509_PUBKEY_free(xpk); |
227 | return ret; | 227 | return ret; |
228 | } | 228 | } |
229 | 229 | ||
230 | /* The following are equivalents but which return RSA and DSA | 230 | /* The following are equivalents but which return RSA and DSA |
231 | * keys | 231 | * keys |
@@ -233,7 +233,7 @@ int i2d_PUBKEY(EVP_PKEY *a, unsigned char **pp) | |||
233 | #ifndef OPENSSL_NO_RSA | 233 | #ifndef OPENSSL_NO_RSA |
234 | RSA *d2i_RSA_PUBKEY(RSA **a, const unsigned char **pp, | 234 | RSA *d2i_RSA_PUBKEY(RSA **a, const unsigned char **pp, |
235 | long length) | 235 | long length) |
236 | { | 236 | { |
237 | EVP_PKEY *pkey; | 237 | EVP_PKEY *pkey; |
238 | RSA *key; | 238 | RSA *key; |
239 | const unsigned char *q; | 239 | const unsigned char *q; |
@@ -245,35 +245,35 @@ RSA *d2i_RSA_PUBKEY(RSA **a, const unsigned char **pp, | |||
245 | if (!key) return NULL; | 245 | if (!key) return NULL; |
246 | *pp = q; | 246 | *pp = q; |
247 | if (a) | 247 | if (a) |
248 | { | 248 | { |
249 | RSA_free(*a); | 249 | RSA_free(*a); |
250 | *a = key; | 250 | *a = key; |
251 | } | ||
252 | return key; | ||
253 | } | 251 | } |
252 | return key; | ||
253 | } | ||
254 | 254 | ||
255 | int i2d_RSA_PUBKEY(RSA *a, unsigned char **pp) | 255 | int i2d_RSA_PUBKEY(RSA *a, unsigned char **pp) |
256 | { | 256 | { |
257 | EVP_PKEY *pktmp; | 257 | EVP_PKEY *pktmp; |
258 | int ret; | 258 | int ret; |
259 | if (!a) return 0; | 259 | if (!a) return 0; |
260 | pktmp = EVP_PKEY_new(); | 260 | pktmp = EVP_PKEY_new(); |
261 | if (!pktmp) | 261 | if (!pktmp) |
262 | { | 262 | { |
263 | ASN1err(ASN1_F_I2D_RSA_PUBKEY, ERR_R_MALLOC_FAILURE); | 263 | ASN1err(ASN1_F_I2D_RSA_PUBKEY, ERR_R_MALLOC_FAILURE); |
264 | return 0; | 264 | return 0; |
265 | } | 265 | } |
266 | EVP_PKEY_set1_RSA(pktmp, a); | 266 | EVP_PKEY_set1_RSA(pktmp, a); |
267 | ret = i2d_PUBKEY(pktmp, pp); | 267 | ret = i2d_PUBKEY(pktmp, pp); |
268 | EVP_PKEY_free(pktmp); | 268 | EVP_PKEY_free(pktmp); |
269 | return ret; | 269 | return ret; |
270 | } | 270 | } |
271 | #endif | 271 | #endif |
272 | 272 | ||
273 | #ifndef OPENSSL_NO_DSA | 273 | #ifndef OPENSSL_NO_DSA |
274 | DSA *d2i_DSA_PUBKEY(DSA **a, const unsigned char **pp, | 274 | DSA *d2i_DSA_PUBKEY(DSA **a, const unsigned char **pp, |
275 | long length) | 275 | long length) |
276 | { | 276 | { |
277 | EVP_PKEY *pkey; | 277 | EVP_PKEY *pkey; |
278 | DSA *key; | 278 | DSA *key; |
279 | const unsigned char *q; | 279 | const unsigned char *q; |
@@ -285,34 +285,34 @@ DSA *d2i_DSA_PUBKEY(DSA **a, const unsigned char **pp, | |||
285 | if (!key) return NULL; | 285 | if (!key) return NULL; |
286 | *pp = q; | 286 | *pp = q; |
287 | if (a) | 287 | if (a) |
288 | { | 288 | { |
289 | DSA_free(*a); | 289 | DSA_free(*a); |
290 | *a = key; | 290 | *a = key; |
291 | } | ||
292 | return key; | ||
293 | } | 291 | } |
292 | return key; | ||
293 | } | ||
294 | 294 | ||
295 | int i2d_DSA_PUBKEY(DSA *a, unsigned char **pp) | 295 | int i2d_DSA_PUBKEY(DSA *a, unsigned char **pp) |
296 | { | 296 | { |
297 | EVP_PKEY *pktmp; | 297 | EVP_PKEY *pktmp; |
298 | int ret; | 298 | int ret; |
299 | if(!a) return 0; | 299 | if(!a) return 0; |
300 | pktmp = EVP_PKEY_new(); | 300 | pktmp = EVP_PKEY_new(); |
301 | if(!pktmp) | 301 | if(!pktmp) |
302 | { | 302 | { |
303 | ASN1err(ASN1_F_I2D_DSA_PUBKEY, ERR_R_MALLOC_FAILURE); | 303 | ASN1err(ASN1_F_I2D_DSA_PUBKEY, ERR_R_MALLOC_FAILURE); |
304 | return 0; | 304 | return 0; |
305 | } | 305 | } |
306 | EVP_PKEY_set1_DSA(pktmp, a); | 306 | EVP_PKEY_set1_DSA(pktmp, a); |
307 | ret = i2d_PUBKEY(pktmp, pp); | 307 | ret = i2d_PUBKEY(pktmp, pp); |
308 | EVP_PKEY_free(pktmp); | 308 | EVP_PKEY_free(pktmp); |
309 | return ret; | 309 | return ret; |
310 | } | 310 | } |
311 | #endif | 311 | #endif |
312 | 312 | ||
313 | #ifndef OPENSSL_NO_EC | 313 | #ifndef OPENSSL_NO_EC |
314 | EC_KEY *d2i_EC_PUBKEY(EC_KEY **a, const unsigned char **pp, long length) | 314 | EC_KEY *d2i_EC_PUBKEY(EC_KEY **a, const unsigned char **pp, long length) |
315 | { | 315 | { |
316 | EVP_PKEY *pkey; | 316 | EVP_PKEY *pkey; |
317 | EC_KEY *key; | 317 | EC_KEY *key; |
318 | const unsigned char *q; | 318 | const unsigned char *q; |
@@ -324,38 +324,38 @@ EC_KEY *d2i_EC_PUBKEY(EC_KEY **a, const unsigned char **pp, long length) | |||
324 | if (!key) return(NULL); | 324 | if (!key) return(NULL); |
325 | *pp = q; | 325 | *pp = q; |
326 | if (a) | 326 | if (a) |
327 | { | 327 | { |
328 | EC_KEY_free(*a); | 328 | EC_KEY_free(*a); |
329 | *a = key; | 329 | *a = key; |
330 | } | ||
331 | return(key); | ||
332 | } | 330 | } |
331 | return(key); | ||
332 | } | ||
333 | 333 | ||
334 | int i2d_EC_PUBKEY(EC_KEY *a, unsigned char **pp) | 334 | int i2d_EC_PUBKEY(EC_KEY *a, unsigned char **pp) |
335 | { | 335 | { |
336 | EVP_PKEY *pktmp; | 336 | EVP_PKEY *pktmp; |
337 | int ret; | 337 | int ret; |
338 | if (!a) return(0); | 338 | if (!a) return(0); |
339 | if ((pktmp = EVP_PKEY_new()) == NULL) | 339 | if ((pktmp = EVP_PKEY_new()) == NULL) |
340 | { | 340 | { |
341 | ASN1err(ASN1_F_I2D_EC_PUBKEY, ERR_R_MALLOC_FAILURE); | 341 | ASN1err(ASN1_F_I2D_EC_PUBKEY, ERR_R_MALLOC_FAILURE); |
342 | return(0); | 342 | return(0); |
343 | } | 343 | } |
344 | EVP_PKEY_set1_EC_KEY(pktmp, a); | 344 | EVP_PKEY_set1_EC_KEY(pktmp, a); |
345 | ret = i2d_PUBKEY(pktmp, pp); | 345 | ret = i2d_PUBKEY(pktmp, pp); |
346 | EVP_PKEY_free(pktmp); | 346 | EVP_PKEY_free(pktmp); |
347 | return(ret); | 347 | return(ret); |
348 | } | 348 | } |
349 | #endif | 349 | #endif |
350 | 350 | ||
351 | int X509_PUBKEY_set0_param(X509_PUBKEY *pub, ASN1_OBJECT *aobj, | 351 | int X509_PUBKEY_set0_param(X509_PUBKEY *pub, ASN1_OBJECT *aobj, |
352 | int ptype, void *pval, | 352 | int ptype, void *pval, |
353 | unsigned char *penc, int penclen) | 353 | unsigned char *penc, int penclen) |
354 | { | 354 | { |
355 | if (!X509_ALGOR_set0(pub->algor, aobj, ptype, pval)) | 355 | if (!X509_ALGOR_set0(pub->algor, aobj, ptype, pval)) |
356 | return 0; | 356 | return 0; |
357 | if (penc) | 357 | if (penc) |
358 | { | 358 | { |
359 | if (pub->public_key->data) | 359 | if (pub->public_key->data) |
360 | free(pub->public_key->data); | 360 | free(pub->public_key->data); |
361 | pub->public_key->data = penc; | 361 | pub->public_key->data = penc; |
@@ -363,23 +363,23 @@ int X509_PUBKEY_set0_param(X509_PUBKEY *pub, ASN1_OBJECT *aobj, | |||
363 | /* Set number of unused bits to zero */ | 363 | /* Set number of unused bits to zero */ |
364 | pub->public_key->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); | 364 | pub->public_key->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); |
365 | pub->public_key->flags|=ASN1_STRING_FLAG_BITS_LEFT; | 365 | pub->public_key->flags|=ASN1_STRING_FLAG_BITS_LEFT; |
366 | } | ||
367 | return 1; | ||
368 | } | 366 | } |
367 | return 1; | ||
368 | } | ||
369 | 369 | ||
370 | int X509_PUBKEY_get0_param(ASN1_OBJECT **ppkalg, | 370 | int X509_PUBKEY_get0_param(ASN1_OBJECT **ppkalg, |
371 | const unsigned char **pk, int *ppklen, | 371 | const unsigned char **pk, int *ppklen, |
372 | X509_ALGOR **pa, | 372 | X509_ALGOR **pa, |
373 | X509_PUBKEY *pub) | 373 | X509_PUBKEY *pub) |
374 | { | 374 | { |
375 | if (ppkalg) | 375 | if (ppkalg) |
376 | *ppkalg = pub->algor->algorithm; | 376 | *ppkalg = pub->algor->algorithm; |
377 | if (pk) | 377 | if (pk) |
378 | { | 378 | { |
379 | *pk = pub->public_key->data; | 379 | *pk = pub->public_key->data; |
380 | *ppklen = pub->public_key->length; | 380 | *ppklen = pub->public_key->length; |
381 | } | 381 | } |
382 | if (pa) | 382 | if (pa) |
383 | *pa = pub->algor; | 383 | *pa = pub->algor; |
384 | return 1; | 384 | return 1; |
385 | } | 385 | } |
diff --git a/src/lib/libcrypto/asn1/x_x509.c b/src/lib/libcrypto/asn1/x_x509.c index 5734f2b069..ff8bd77024 100644 --- a/src/lib/libcrypto/asn1/x_x509.c +++ b/src/lib/libcrypto/asn1/x_x509.c | |||
@@ -143,20 +143,20 @@ IMPLEMENT_ASN1_DUP_FUNCTION(X509) | |||
143 | 143 | ||
144 | int X509_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, | 144 | int X509_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, |
145 | CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func) | 145 | CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func) |
146 | { | 146 | { |
147 | return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_X509, argl, argp, | 147 | return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_X509, argl, argp, |
148 | new_func, dup_func, free_func); | 148 | new_func, dup_func, free_func); |
149 | } | 149 | } |
150 | 150 | ||
151 | int X509_set_ex_data(X509 *r, int idx, void *arg) | 151 | int X509_set_ex_data(X509 *r, int idx, void *arg) |
152 | { | 152 | { |
153 | return(CRYPTO_set_ex_data(&r->ex_data,idx,arg)); | 153 | return(CRYPTO_set_ex_data(&r->ex_data,idx,arg)); |
154 | } | 154 | } |
155 | 155 | ||
156 | void *X509_get_ex_data(X509 *r, int idx) | 156 | void *X509_get_ex_data(X509 *r, int idx) |
157 | { | 157 | { |
158 | return(CRYPTO_get_ex_data(&r->ex_data,idx)); | 158 | return(CRYPTO_get_ex_data(&r->ex_data,idx)); |
159 | } | 159 | } |
160 | 160 | ||
161 | /* X509_AUX ASN1 routines. X509_AUX is the name given to | 161 | /* X509_AUX ASN1 routines. X509_AUX is the name given to |
162 | * a certificate with extra info tagged on the end. Since these | 162 | * a certificate with extra info tagged on the end. Since these |
diff --git a/src/lib/libcrypto/asn1/x_x509a.c b/src/lib/libcrypto/asn1/x_x509a.c index b603f82de7..9449f517be 100644 --- a/src/lib/libcrypto/asn1/x_x509a.c +++ b/src/lib/libcrypto/asn1/x_x509a.c | |||
@@ -92,13 +92,13 @@ int X509_alias_set1(X509 *x, unsigned char *name, int len) | |||
92 | { | 92 | { |
93 | X509_CERT_AUX *aux; | 93 | X509_CERT_AUX *aux; |
94 | if (!name) | 94 | if (!name) |
95 | { | 95 | { |
96 | if (!x || !x->aux || !x->aux->alias) | 96 | if (!x || !x->aux || !x->aux->alias) |
97 | return 1; | 97 | return 1; |
98 | ASN1_UTF8STRING_free(x->aux->alias); | 98 | ASN1_UTF8STRING_free(x->aux->alias); |
99 | x->aux->alias = NULL; | 99 | x->aux->alias = NULL; |
100 | return 1; | 100 | return 1; |
101 | } | 101 | } |
102 | if(!(aux = aux_get(x))) return 0; | 102 | if(!(aux = aux_get(x))) return 0; |
103 | if(!aux->alias && !(aux->alias = ASN1_UTF8STRING_new())) return 0; | 103 | if(!aux->alias && !(aux->alias = ASN1_UTF8STRING_new())) return 0; |
104 | return ASN1_STRING_set(aux->alias, name, len); | 104 | return ASN1_STRING_set(aux->alias, name, len); |
@@ -108,13 +108,13 @@ int X509_keyid_set1(X509 *x, unsigned char *id, int len) | |||
108 | { | 108 | { |
109 | X509_CERT_AUX *aux; | 109 | X509_CERT_AUX *aux; |
110 | if (!id) | 110 | if (!id) |
111 | { | 111 | { |
112 | if (!x || !x->aux || !x->aux->keyid) | 112 | if (!x || !x->aux || !x->aux->keyid) |
113 | return 1; | 113 | return 1; |
114 | ASN1_OCTET_STRING_free(x->aux->keyid); | 114 | ASN1_OCTET_STRING_free(x->aux->keyid); |
115 | x->aux->keyid = NULL; | 115 | x->aux->keyid = NULL; |
116 | return 1; | 116 | return 1; |
117 | } | 117 | } |
118 | if(!(aux = aux_get(x))) return 0; | 118 | if(!(aux = aux_get(x))) return 0; |
119 | if(!aux->keyid && !(aux->keyid = ASN1_OCTET_STRING_new())) return 0; | 119 | if(!aux->keyid && !(aux->keyid = ASN1_OCTET_STRING_new())) return 0; |
120 | return ASN1_STRING_set(aux->keyid, id, len); | 120 | return ASN1_STRING_set(aux->keyid, id, len); |
diff --git a/src/lib/libssl/src/crypto/asn1/a_digest.c b/src/lib/libssl/src/crypto/asn1/a_digest.c index 0d463d409b..e87d4396df 100644 --- a/src/lib/libssl/src/crypto/asn1/a_digest.c +++ b/src/lib/libssl/src/crypto/asn1/a_digest.c | |||
@@ -72,7 +72,7 @@ | |||
72 | 72 | ||
73 | int ASN1_item_digest(const ASN1_ITEM *it, const EVP_MD *type, void *asn, | 73 | int ASN1_item_digest(const ASN1_ITEM *it, const EVP_MD *type, void *asn, |
74 | unsigned char *md, unsigned int *len) | 74 | unsigned char *md, unsigned int *len) |
75 | { | 75 | { |
76 | int i; | 76 | int i; |
77 | unsigned char *str = NULL; | 77 | unsigned char *str = NULL; |
78 | 78 | ||
@@ -83,4 +83,4 @@ int ASN1_item_digest(const ASN1_ITEM *it, const EVP_MD *type, void *asn, | |||
83 | return 0; | 83 | return 0; |
84 | free(str); | 84 | free(str); |
85 | return(1); | 85 | return(1); |
86 | } | 86 | } |
diff --git a/src/lib/libssl/src/crypto/asn1/a_dup.c b/src/lib/libssl/src/crypto/asn1/a_dup.c index e825b9c2d4..4482a89337 100644 --- a/src/lib/libssl/src/crypto/asn1/a_dup.c +++ b/src/lib/libssl/src/crypto/asn1/a_dup.c | |||
@@ -63,7 +63,7 @@ | |||
63 | #ifndef NO_OLD_ASN1 | 63 | #ifndef NO_OLD_ASN1 |
64 | 64 | ||
65 | void *ASN1_dup(i2d_of_void *i2d, d2i_of_void *d2i, void *x) | 65 | void *ASN1_dup(i2d_of_void *i2d, d2i_of_void *d2i, void *x) |
66 | { | 66 | { |
67 | unsigned char *b,*p; | 67 | unsigned char *b,*p; |
68 | const unsigned char *p2; | 68 | const unsigned char *p2; |
69 | int i; | 69 | int i; |
@@ -74,14 +74,16 @@ void *ASN1_dup(i2d_of_void *i2d, d2i_of_void *d2i, void *x) | |||
74 | i=i2d(x,NULL); | 74 | i=i2d(x,NULL); |
75 | b=malloc(i+10); | 75 | b=malloc(i+10); |
76 | if (b == NULL) | 76 | if (b == NULL) |
77 | { ASN1err(ASN1_F_ASN1_DUP,ERR_R_MALLOC_FAILURE); return(NULL); } | 77 | { |
78 | ASN1err(ASN1_F_ASN1_DUP,ERR_R_MALLOC_FAILURE); return(NULL); | ||
79 | } | ||
78 | p= b; | 80 | p= b; |
79 | i=i2d(x,&p); | 81 | i=i2d(x,&p); |
80 | p2= b; | 82 | p2= b; |
81 | ret=d2i(NULL,&p2,i); | 83 | ret=d2i(NULL,&p2,i); |
82 | free(b); | 84 | free(b); |
83 | return(ret); | 85 | return(ret); |
84 | } | 86 | } |
85 | 87 | ||
86 | #endif | 88 | #endif |
87 | 89 | ||
@@ -91,7 +93,7 @@ void *ASN1_dup(i2d_of_void *i2d, d2i_of_void *d2i, void *x) | |||
91 | */ | 93 | */ |
92 | 94 | ||
93 | void *ASN1_item_dup(const ASN1_ITEM *it, void *x) | 95 | void *ASN1_item_dup(const ASN1_ITEM *it, void *x) |
94 | { | 96 | { |
95 | unsigned char *b = NULL; | 97 | unsigned char *b = NULL; |
96 | const unsigned char *p; | 98 | const unsigned char *p; |
97 | long i; | 99 | long i; |
@@ -101,9 +103,11 @@ void *ASN1_item_dup(const ASN1_ITEM *it, void *x) | |||
101 | 103 | ||
102 | i=ASN1_item_i2d(x,&b,it); | 104 | i=ASN1_item_i2d(x,&b,it); |
103 | if (b == NULL) | 105 | if (b == NULL) |
104 | { ASN1err(ASN1_F_ASN1_ITEM_DUP,ERR_R_MALLOC_FAILURE); return(NULL); } | 106 | { |
107 | ASN1err(ASN1_F_ASN1_ITEM_DUP,ERR_R_MALLOC_FAILURE); return(NULL); | ||
108 | } | ||
105 | p= b; | 109 | p= b; |
106 | ret=ASN1_item_d2i(NULL,&p,i, it); | 110 | ret=ASN1_item_d2i(NULL,&p,i, it); |
107 | free(b); | 111 | free(b); |
108 | return(ret); | 112 | return(ret); |
109 | } | 113 | } |
diff --git a/src/lib/libssl/src/crypto/asn1/a_enum.c b/src/lib/libssl/src/crypto/asn1/a_enum.c index c1154dde0a..77c7c2cd88 100644 --- a/src/lib/libssl/src/crypto/asn1/a_enum.c +++ b/src/lib/libssl/src/crypto/asn1/a_enum.c | |||
@@ -67,7 +67,7 @@ | |||
67 | */ | 67 | */ |
68 | 68 | ||
69 | int ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v) | 69 | int ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v) |
70 | { | 70 | { |
71 | int j,k; | 71 | int j,k; |
72 | unsigned int i; | 72 | unsigned int i; |
73 | unsigned char buf[sizeof(long)+1]; | 73 | unsigned char buf[sizeof(long)+1]; |
@@ -75,39 +75,39 @@ int ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v) | |||
75 | 75 | ||
76 | a->type=V_ASN1_ENUMERATED; | 76 | a->type=V_ASN1_ENUMERATED; |
77 | if (a->length < (int)(sizeof(long)+1)) | 77 | if (a->length < (int)(sizeof(long)+1)) |
78 | { | 78 | { |
79 | if (a->data != NULL) | 79 | if (a->data != NULL) |
80 | free(a->data); | 80 | free(a->data); |
81 | if ((a->data=(unsigned char *)malloc(sizeof(long)+1)) != NULL) | 81 | if ((a->data=(unsigned char *)malloc(sizeof(long)+1)) != NULL) |
82 | memset((char *)a->data,0,sizeof(long)+1); | 82 | memset((char *)a->data,0,sizeof(long)+1); |
83 | } | 83 | } |
84 | if (a->data == NULL) | 84 | if (a->data == NULL) |
85 | { | 85 | { |
86 | ASN1err(ASN1_F_ASN1_ENUMERATED_SET,ERR_R_MALLOC_FAILURE); | 86 | ASN1err(ASN1_F_ASN1_ENUMERATED_SET,ERR_R_MALLOC_FAILURE); |
87 | return(0); | 87 | return(0); |
88 | } | 88 | } |
89 | d=v; | 89 | d=v; |
90 | if (d < 0) | 90 | if (d < 0) |
91 | { | 91 | { |
92 | d= -d; | 92 | d= -d; |
93 | a->type=V_ASN1_NEG_ENUMERATED; | 93 | a->type=V_ASN1_NEG_ENUMERATED; |
94 | } | 94 | } |
95 | 95 | ||
96 | for (i=0; i<sizeof(long); i++) | 96 | for (i=0; i<sizeof(long); i++) |
97 | { | 97 | { |
98 | if (d == 0) break; | 98 | if (d == 0) break; |
99 | buf[i]=(int)d&0xff; | 99 | buf[i]=(int)d&0xff; |
100 | d>>=8; | 100 | d>>=8; |
101 | } | 101 | } |
102 | j=0; | 102 | j=0; |
103 | for (k=i-1; k >=0; k--) | 103 | for (k=i-1; k >=0; k--) |
104 | a->data[j++]=buf[k]; | 104 | a->data[j++]=buf[k]; |
105 | a->length=j; | 105 | a->length=j; |
106 | return(1); | 106 | return(1); |
107 | } | 107 | } |
108 | 108 | ||
109 | long ASN1_ENUMERATED_get(ASN1_ENUMERATED *a) | 109 | long ASN1_ENUMERATED_get(ASN1_ENUMERATED *a) |
110 | { | 110 | { |
111 | int neg=0,i; | 111 | int neg=0,i; |
112 | long r=0; | 112 | long r=0; |
113 | 113 | ||
@@ -119,24 +119,24 @@ long ASN1_ENUMERATED_get(ASN1_ENUMERATED *a) | |||
119 | return -1; | 119 | return -1; |
120 | 120 | ||
121 | if (a->length > (int)sizeof(long)) | 121 | if (a->length > (int)sizeof(long)) |
122 | { | 122 | { |
123 | /* hmm... a bit ugly */ | 123 | /* hmm... a bit ugly */ |
124 | return(0xffffffffL); | 124 | return(0xffffffffL); |
125 | } | 125 | } |
126 | if (a->data == NULL) | 126 | if (a->data == NULL) |
127 | return 0; | 127 | return 0; |
128 | 128 | ||
129 | for (i=0; i<a->length; i++) | 129 | for (i=0; i<a->length; i++) |
130 | { | 130 | { |
131 | r<<=8; | 131 | r<<=8; |
132 | r|=(unsigned char)a->data[i]; | 132 | r|=(unsigned char)a->data[i]; |
133 | } | 133 | } |
134 | if (neg) r= -r; | 134 | if (neg) r= -r; |
135 | return(r); | 135 | return(r); |
136 | } | 136 | } |
137 | 137 | ||
138 | ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(BIGNUM *bn, ASN1_ENUMERATED *ai) | 138 | ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(BIGNUM *bn, ASN1_ENUMERATED *ai) |
139 | { | 139 | { |
140 | ASN1_ENUMERATED *ret; | 140 | ASN1_ENUMERATED *ret; |
141 | int len,j; | 141 | int len,j; |
142 | 142 | ||
@@ -145,38 +145,38 @@ ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(BIGNUM *bn, ASN1_ENUMERATED *ai) | |||
145 | else | 145 | else |
146 | ret=ai; | 146 | ret=ai; |
147 | if (ret == NULL) | 147 | if (ret == NULL) |
148 | { | 148 | { |
149 | ASN1err(ASN1_F_BN_TO_ASN1_ENUMERATED,ERR_R_NESTED_ASN1_ERROR); | 149 | ASN1err(ASN1_F_BN_TO_ASN1_ENUMERATED,ERR_R_NESTED_ASN1_ERROR); |
150 | goto err; | 150 | goto err; |
151 | } | 151 | } |
152 | if(BN_is_negative(bn)) ret->type = V_ASN1_NEG_ENUMERATED; | 152 | if(BN_is_negative(bn)) ret->type = V_ASN1_NEG_ENUMERATED; |
153 | else ret->type=V_ASN1_ENUMERATED; | 153 | else ret->type=V_ASN1_ENUMERATED; |
154 | j=BN_num_bits(bn); | 154 | j=BN_num_bits(bn); |
155 | len=((j == 0)?0:((j/8)+1)); | 155 | len=((j == 0)?0:((j/8)+1)); |
156 | if (ret->length < len+4) | 156 | if (ret->length < len+4) |
157 | { | 157 | { |
158 | unsigned char *new_data=realloc(ret->data, len+4); | 158 | unsigned char *new_data=realloc(ret->data, len+4); |
159 | if (!new_data) | 159 | if (!new_data) |
160 | { | 160 | { |
161 | ASN1err(ASN1_F_BN_TO_ASN1_ENUMERATED,ERR_R_MALLOC_FAILURE); | 161 | ASN1err(ASN1_F_BN_TO_ASN1_ENUMERATED,ERR_R_MALLOC_FAILURE); |
162 | goto err; | 162 | goto err; |
163 | } | ||
164 | ret->data=new_data; | ||
165 | } | 163 | } |
164 | ret->data=new_data; | ||
165 | } | ||
166 | 166 | ||
167 | ret->length=BN_bn2bin(bn,ret->data); | 167 | ret->length=BN_bn2bin(bn,ret->data); |
168 | return(ret); | 168 | return(ret); |
169 | err: | 169 | err: |
170 | if (ret != ai) M_ASN1_ENUMERATED_free(ret); | 170 | if (ret != ai) M_ASN1_ENUMERATED_free(ret); |
171 | return(NULL); | 171 | return(NULL); |
172 | } | 172 | } |
173 | 173 | ||
174 | BIGNUM *ASN1_ENUMERATED_to_BN(ASN1_ENUMERATED *ai, BIGNUM *bn) | 174 | BIGNUM *ASN1_ENUMERATED_to_BN(ASN1_ENUMERATED *ai, BIGNUM *bn) |
175 | { | 175 | { |
176 | BIGNUM *ret; | 176 | BIGNUM *ret; |
177 | 177 | ||
178 | if ((ret=BN_bin2bn(ai->data,ai->length,bn)) == NULL) | 178 | if ((ret=BN_bin2bn(ai->data,ai->length,bn)) == NULL) |
179 | ASN1err(ASN1_F_ASN1_ENUMERATED_TO_BN,ASN1_R_BN_LIB); | 179 | ASN1err(ASN1_F_ASN1_ENUMERATED_TO_BN,ASN1_R_BN_LIB); |
180 | else if(ai->type == V_ASN1_NEG_ENUMERATED) BN_set_negative(ret,1); | 180 | else if(ai->type == V_ASN1_NEG_ENUMERATED) BN_set_negative(ret,1); |
181 | return(ret); | 181 | return(ret); |
182 | } | 182 | } |
diff --git a/src/lib/libssl/src/crypto/asn1/a_gentm.c b/src/lib/libssl/src/crypto/asn1/a_gentm.c index 86666e7a20..54016dc8e7 100644 --- a/src/lib/libssl/src/crypto/asn1/a_gentm.c +++ b/src/lib/libssl/src/crypto/asn1/a_gentm.c | |||
@@ -67,41 +67,41 @@ | |||
67 | #if 0 | 67 | #if 0 |
68 | 68 | ||
69 | int i2d_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME *a, unsigned char **pp) | 69 | int i2d_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME *a, unsigned char **pp) |
70 | { | 70 | { |
71 | return(i2d_ASN1_bytes((ASN1_STRING *)a,pp, | 71 | return(i2d_ASN1_bytes((ASN1_STRING *)a,pp, |
72 | V_ASN1_GENERALIZEDTIME,V_ASN1_UNIVERSAL)); | 72 | V_ASN1_GENERALIZEDTIME,V_ASN1_UNIVERSAL)); |
73 | } | 73 | } |
74 | 74 | ||
75 | 75 | ||
76 | ASN1_GENERALIZEDTIME *d2i_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME **a, | 76 | ASN1_GENERALIZEDTIME *d2i_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME **a, |
77 | unsigned char **pp, long length) | 77 | unsigned char **pp, long length) |
78 | { | 78 | { |
79 | ASN1_GENERALIZEDTIME *ret=NULL; | 79 | ASN1_GENERALIZEDTIME *ret=NULL; |
80 | 80 | ||
81 | ret=(ASN1_GENERALIZEDTIME *)d2i_ASN1_bytes((ASN1_STRING **)a,pp,length, | 81 | ret=(ASN1_GENERALIZEDTIME *)d2i_ASN1_bytes((ASN1_STRING **)a,pp,length, |
82 | V_ASN1_GENERALIZEDTIME,V_ASN1_UNIVERSAL); | 82 | V_ASN1_GENERALIZEDTIME,V_ASN1_UNIVERSAL); |
83 | if (ret == NULL) | 83 | if (ret == NULL) |
84 | { | 84 | { |
85 | ASN1err(ASN1_F_D2I_ASN1_GENERALIZEDTIME,ERR_R_NESTED_ASN1_ERROR); | 85 | ASN1err(ASN1_F_D2I_ASN1_GENERALIZEDTIME,ERR_R_NESTED_ASN1_ERROR); |
86 | return(NULL); | 86 | return(NULL); |
87 | } | 87 | } |
88 | if (!ASN1_GENERALIZEDTIME_check(ret)) | 88 | if (!ASN1_GENERALIZEDTIME_check(ret)) |
89 | { | 89 | { |
90 | ASN1err(ASN1_F_D2I_ASN1_GENERALIZEDTIME,ASN1_R_INVALID_TIME_FORMAT); | 90 | ASN1err(ASN1_F_D2I_ASN1_GENERALIZEDTIME,ASN1_R_INVALID_TIME_FORMAT); |
91 | goto err; | 91 | goto err; |
92 | } | 92 | } |
93 | 93 | ||
94 | return(ret); | 94 | return(ret); |
95 | err: | 95 | err: |
96 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) | 96 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) |
97 | M_ASN1_GENERALIZEDTIME_free(ret); | 97 | M_ASN1_GENERALIZEDTIME_free(ret); |
98 | return(NULL); | 98 | return(NULL); |
99 | } | 99 | } |
100 | 100 | ||
101 | #endif | 101 | #endif |
102 | 102 | ||
103 | int ASN1_GENERALIZEDTIME_check(ASN1_GENERALIZEDTIME *d) | 103 | int ASN1_GENERALIZEDTIME_check(ASN1_GENERALIZEDTIME *d) |
104 | { | 104 | { |
105 | static const int min[9]={ 0, 0, 1, 1, 0, 0, 0, 0, 0}; | 105 | static const int min[9]={ 0, 0, 1, 1, 0, 0, 0, 0, 0}; |
106 | static const int max[9]={99, 99,12,31,23,59,59,12,59}; | 106 | static const int max[9]={99, 99,12,31,23,59,59,12,59}; |
107 | char *a; | 107 | char *a; |
@@ -117,10 +117,10 @@ int ASN1_GENERALIZEDTIME_check(ASN1_GENERALIZEDTIME *d) | |||
117 | */ | 117 | */ |
118 | if (l < 13) goto err; | 118 | if (l < 13) goto err; |
119 | for (i=0; i<7; i++) | 119 | for (i=0; i<7; i++) |
120 | { | 120 | { |
121 | if ((i == 6) && ((a[o] == 'Z') || | 121 | if ((i == 6) && ((a[o] == 'Z') || |
122 | (a[o] == '+') || (a[o] == '-'))) | 122 | (a[o] == '+') || (a[o] == '-'))) |
123 | { i++; break; } | 123 | { i++; break; } |
124 | if ((a[o] < '0') || (a[o] > '9')) goto err; | 124 | if ((a[o] < '0') || (a[o] > '9')) goto err; |
125 | n= a[o]-'0'; | 125 | n= a[o]-'0'; |
126 | if (++o > l) goto err; | 126 | if (++o > l) goto err; |
@@ -130,28 +130,28 @@ int ASN1_GENERALIZEDTIME_check(ASN1_GENERALIZEDTIME *d) | |||
130 | if (++o > l) goto err; | 130 | if (++o > l) goto err; |
131 | 131 | ||
132 | if ((n < min[i]) || (n > max[i])) goto err; | 132 | if ((n < min[i]) || (n > max[i])) goto err; |
133 | } | 133 | } |
134 | /* Optional fractional seconds: decimal point followed by one | 134 | /* Optional fractional seconds: decimal point followed by one |
135 | * or more digits. | 135 | * or more digits. |
136 | */ | 136 | */ |
137 | if (a[o] == '.') | 137 | if (a[o] == '.') |
138 | { | 138 | { |
139 | if (++o > l) goto err; | 139 | if (++o > l) goto err; |
140 | i = o; | 140 | i = o; |
141 | while ((a[o] >= '0') && (a[o] <= '9') && (o <= l)) | 141 | while ((a[o] >= '0') && (a[o] <= '9') && (o <= l)) |
142 | o++; | 142 | o++; |
143 | /* Must have at least one digit after decimal point */ | 143 | /* Must have at least one digit after decimal point */ |
144 | if (i == o) goto err; | 144 | if (i == o) goto err; |
145 | } | 145 | } |
146 | 146 | ||
147 | if (a[o] == 'Z') | 147 | if (a[o] == 'Z') |
148 | o++; | 148 | o++; |
149 | else if ((a[o] == '+') || (a[o] == '-')) | 149 | else if ((a[o] == '+') || (a[o] == '-')) |
150 | { | 150 | { |
151 | o++; | 151 | o++; |
152 | if (o+4 > l) goto err; | 152 | if (o+4 > l) goto err; |
153 | for (i=7; i<9; i++) | 153 | for (i=7; i<9; i++) |
154 | { | 154 | { |
155 | if ((a[o] < '0') || (a[o] > '9')) goto err; | 155 | if ((a[o] < '0') || (a[o] > '9')) goto err; |
156 | n= a[o]-'0'; | 156 | n= a[o]-'0'; |
157 | o++; | 157 | o++; |
@@ -159,49 +159,49 @@ int ASN1_GENERALIZEDTIME_check(ASN1_GENERALIZEDTIME *d) | |||
159 | n=(n*10)+ a[o]-'0'; | 159 | n=(n*10)+ a[o]-'0'; |
160 | if ((n < min[i]) || (n > max[i])) goto err; | 160 | if ((n < min[i]) || (n > max[i])) goto err; |
161 | o++; | 161 | o++; |
162 | } | ||
163 | } | 162 | } |
163 | } | ||
164 | else | 164 | else |
165 | { | 165 | { |
166 | /* Missing time zone information. */ | 166 | /* Missing time zone information. */ |
167 | goto err; | 167 | goto err; |
168 | } | 168 | } |
169 | return(o == l); | 169 | return(o == l); |
170 | err: | 170 | err: |
171 | return(0); | 171 | return(0); |
172 | } | 172 | } |
173 | 173 | ||
174 | int ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s, const char *str) | 174 | int ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s, const char *str) |
175 | { | 175 | { |
176 | ASN1_GENERALIZEDTIME t; | 176 | ASN1_GENERALIZEDTIME t; |
177 | 177 | ||
178 | t.type=V_ASN1_GENERALIZEDTIME; | 178 | t.type=V_ASN1_GENERALIZEDTIME; |
179 | t.length=strlen(str); | 179 | t.length=strlen(str); |
180 | t.data=(unsigned char *)str; | 180 | t.data=(unsigned char *)str; |
181 | if (ASN1_GENERALIZEDTIME_check(&t)) | 181 | if (ASN1_GENERALIZEDTIME_check(&t)) |
182 | { | 182 | { |
183 | if (s != NULL) | 183 | if (s != NULL) |
184 | { | 184 | { |
185 | if (!ASN1_STRING_set((ASN1_STRING *)s, | 185 | if (!ASN1_STRING_set((ASN1_STRING *)s, |
186 | (unsigned char *)str,t.length)) | 186 | (unsigned char *)str,t.length)) |
187 | return 0; | 187 | return 0; |
188 | s->type=V_ASN1_GENERALIZEDTIME; | 188 | s->type=V_ASN1_GENERALIZEDTIME; |
189 | } | ||
190 | return(1); | ||
191 | } | 189 | } |
190 | return(1); | ||
191 | } | ||
192 | else | 192 | else |
193 | return(0); | 193 | return(0); |
194 | } | 194 | } |
195 | 195 | ||
196 | ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s, | 196 | ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s, |
197 | time_t t) | 197 | time_t t) |
198 | { | 198 | { |
199 | return ASN1_GENERALIZEDTIME_adj(s, t, 0, 0); | 199 | return ASN1_GENERALIZEDTIME_adj(s, t, 0, 0); |
200 | } | 200 | } |
201 | 201 | ||
202 | ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_adj(ASN1_GENERALIZEDTIME *s, | 202 | ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_adj(ASN1_GENERALIZEDTIME *s, |
203 | time_t t, int offset_day, long offset_sec) | 203 | time_t t, int offset_day, long offset_sec) |
204 | { | 204 | { |
205 | char *p; | 205 | char *p; |
206 | struct tm *ts; | 206 | struct tm *ts; |
207 | struct tm data; | 207 | struct tm data; |
@@ -217,29 +217,29 @@ ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_adj(ASN1_GENERALIZEDTIME *s, | |||
217 | return(NULL); | 217 | return(NULL); |
218 | 218 | ||
219 | if (offset_day || offset_sec) | 219 | if (offset_day || offset_sec) |
220 | { | 220 | { |
221 | if (!OPENSSL_gmtime_adj(ts, offset_day, offset_sec)) | 221 | if (!OPENSSL_gmtime_adj(ts, offset_day, offset_sec)) |
222 | return NULL; | 222 | return NULL; |
223 | } | 223 | } |
224 | 224 | ||
225 | p=(char *)s->data; | 225 | p=(char *)s->data; |
226 | if ((p == NULL) || ((size_t)s->length < len)) | 226 | if ((p == NULL) || ((size_t)s->length < len)) |
227 | { | 227 | { |
228 | p=malloc(len); | 228 | p=malloc(len); |
229 | if (p == NULL) | 229 | if (p == NULL) |
230 | { | 230 | { |
231 | ASN1err(ASN1_F_ASN1_GENERALIZEDTIME_ADJ, | 231 | ASN1err(ASN1_F_ASN1_GENERALIZEDTIME_ADJ, |
232 | ERR_R_MALLOC_FAILURE); | 232 | ERR_R_MALLOC_FAILURE); |
233 | return(NULL); | 233 | return(NULL); |
234 | } | 234 | } |
235 | if (s->data != NULL) | 235 | if (s->data != NULL) |
236 | free(s->data); | 236 | free(s->data); |
237 | s->data=(unsigned char *)p; | 237 | s->data=(unsigned char *)p; |
238 | } | 238 | } |
239 | 239 | ||
240 | (void) snprintf(p,len,"%04d%02d%02d%02d%02d%02dZ",ts->tm_year + 1900, | 240 | (void) snprintf(p,len,"%04d%02d%02d%02d%02d%02dZ",ts->tm_year + 1900, |
241 | ts->tm_mon+1,ts->tm_mday,ts->tm_hour,ts->tm_min,ts->tm_sec); | 241 | ts->tm_mon+1,ts->tm_mday,ts->tm_hour,ts->tm_min,ts->tm_sec); |
242 | s->length=strlen(p); | 242 | s->length=strlen(p); |
243 | s->type=V_ASN1_GENERALIZEDTIME; | 243 | s->type=V_ASN1_GENERALIZEDTIME; |
244 | return(s); | 244 | return(s); |
245 | } | 245 | } |
diff --git a/src/lib/libssl/src/crypto/asn1/a_i2d_fp.c b/src/lib/libssl/src/crypto/asn1/a_i2d_fp.c index 484bcd66eb..52bedb3f73 100644 --- a/src/lib/libssl/src/crypto/asn1/a_i2d_fp.c +++ b/src/lib/libssl/src/crypto/asn1/a_i2d_fp.c | |||
@@ -65,24 +65,24 @@ | |||
65 | 65 | ||
66 | #ifndef OPENSSL_NO_FP_API | 66 | #ifndef OPENSSL_NO_FP_API |
67 | int ASN1_i2d_fp(i2d_of_void *i2d, FILE *out, void *x) | 67 | int ASN1_i2d_fp(i2d_of_void *i2d, FILE *out, void *x) |
68 | { | 68 | { |
69 | BIO *b; | 69 | BIO *b; |
70 | int ret; | 70 | int ret; |
71 | 71 | ||
72 | if ((b=BIO_new(BIO_s_file())) == NULL) | 72 | if ((b=BIO_new(BIO_s_file())) == NULL) |
73 | { | 73 | { |
74 | ASN1err(ASN1_F_ASN1_I2D_FP,ERR_R_BUF_LIB); | 74 | ASN1err(ASN1_F_ASN1_I2D_FP,ERR_R_BUF_LIB); |
75 | return(0); | 75 | return(0); |
76 | } | 76 | } |
77 | BIO_set_fp(b,out,BIO_NOCLOSE); | 77 | BIO_set_fp(b,out,BIO_NOCLOSE); |
78 | ret=ASN1_i2d_bio(i2d,b,x); | 78 | ret=ASN1_i2d_bio(i2d,b,x); |
79 | BIO_free(b); | 79 | BIO_free(b); |
80 | return(ret); | 80 | return(ret); |
81 | } | 81 | } |
82 | #endif | 82 | #endif |
83 | 83 | ||
84 | int ASN1_i2d_bio(i2d_of_void *i2d, BIO *out, unsigned char *x) | 84 | int ASN1_i2d_bio(i2d_of_void *i2d, BIO *out, unsigned char *x) |
85 | { | 85 | { |
86 | char *b; | 86 | char *b; |
87 | unsigned char *p; | 87 | unsigned char *p; |
88 | int i,j=0,n,ret=1; | 88 | int i,j=0,n,ret=1; |
@@ -90,74 +90,74 @@ int ASN1_i2d_bio(i2d_of_void *i2d, BIO *out, unsigned char *x) | |||
90 | n=i2d(x,NULL); | 90 | n=i2d(x,NULL); |
91 | b=(char *)malloc(n); | 91 | b=(char *)malloc(n); |
92 | if (b == NULL) | 92 | if (b == NULL) |
93 | { | 93 | { |
94 | ASN1err(ASN1_F_ASN1_I2D_BIO,ERR_R_MALLOC_FAILURE); | 94 | ASN1err(ASN1_F_ASN1_I2D_BIO,ERR_R_MALLOC_FAILURE); |
95 | return(0); | 95 | return(0); |
96 | } | 96 | } |
97 | 97 | ||
98 | p=(unsigned char *)b; | 98 | p=(unsigned char *)b; |
99 | i2d(x,&p); | 99 | i2d(x,&p); |
100 | 100 | ||
101 | for (;;) | 101 | for (;;) |
102 | { | 102 | { |
103 | i=BIO_write(out,&(b[j]),n); | 103 | i=BIO_write(out,&(b[j]),n); |
104 | if (i == n) break; | 104 | if (i == n) break; |
105 | if (i <= 0) | 105 | if (i <= 0) |
106 | { | 106 | { |
107 | ret=0; | 107 | ret=0; |
108 | break; | 108 | break; |
109 | } | 109 | } |
110 | j+=i; | 110 | j+=i; |
111 | n-=i; | 111 | n-=i; |
112 | } | 112 | } |
113 | free(b); | 113 | free(b); |
114 | return(ret); | 114 | return(ret); |
115 | } | 115 | } |
116 | 116 | ||
117 | #endif | 117 | #endif |
118 | 118 | ||
119 | #ifndef OPENSSL_NO_FP_API | 119 | #ifndef OPENSSL_NO_FP_API |
120 | int ASN1_item_i2d_fp(const ASN1_ITEM *it, FILE *out, void *x) | 120 | int ASN1_item_i2d_fp(const ASN1_ITEM *it, FILE *out, void *x) |
121 | { | 121 | { |
122 | BIO *b; | 122 | BIO *b; |
123 | int ret; | 123 | int ret; |
124 | 124 | ||
125 | if ((b=BIO_new(BIO_s_file())) == NULL) | 125 | if ((b=BIO_new(BIO_s_file())) == NULL) |
126 | { | 126 | { |
127 | ASN1err(ASN1_F_ASN1_ITEM_I2D_FP,ERR_R_BUF_LIB); | 127 | ASN1err(ASN1_F_ASN1_ITEM_I2D_FP,ERR_R_BUF_LIB); |
128 | return(0); | 128 | return(0); |
129 | } | 129 | } |
130 | BIO_set_fp(b,out,BIO_NOCLOSE); | 130 | BIO_set_fp(b,out,BIO_NOCLOSE); |
131 | ret=ASN1_item_i2d_bio(it,b,x); | 131 | ret=ASN1_item_i2d_bio(it,b,x); |
132 | BIO_free(b); | 132 | BIO_free(b); |
133 | return(ret); | 133 | return(ret); |
134 | } | 134 | } |
135 | #endif | 135 | #endif |
136 | 136 | ||
137 | int ASN1_item_i2d_bio(const ASN1_ITEM *it, BIO *out, void *x) | 137 | int ASN1_item_i2d_bio(const ASN1_ITEM *it, BIO *out, void *x) |
138 | { | 138 | { |
139 | unsigned char *b = NULL; | 139 | unsigned char *b = NULL; |
140 | int i,j=0,n,ret=1; | 140 | int i,j=0,n,ret=1; |
141 | 141 | ||
142 | n = ASN1_item_i2d(x, &b, it); | 142 | n = ASN1_item_i2d(x, &b, it); |
143 | if (b == NULL) | 143 | if (b == NULL) |
144 | { | 144 | { |
145 | ASN1err(ASN1_F_ASN1_ITEM_I2D_BIO,ERR_R_MALLOC_FAILURE); | 145 | ASN1err(ASN1_F_ASN1_ITEM_I2D_BIO,ERR_R_MALLOC_FAILURE); |
146 | return(0); | 146 | return(0); |
147 | } | 147 | } |
148 | 148 | ||
149 | for (;;) | 149 | for (;;) |
150 | { | 150 | { |
151 | i=BIO_write(out,&(b[j]),n); | 151 | i=BIO_write(out,&(b[j]),n); |
152 | if (i == n) break; | 152 | if (i == n) break; |
153 | if (i <= 0) | 153 | if (i <= 0) |
154 | { | 154 | { |
155 | ret=0; | 155 | ret=0; |
156 | break; | 156 | break; |
157 | } | 157 | } |
158 | j+=i; | 158 | j+=i; |
159 | n-=i; | 159 | n-=i; |
160 | } | 160 | } |
161 | free(b); | 161 | free(b); |
162 | return(ret); | 162 | return(ret); |
163 | } | 163 | } |
diff --git a/src/lib/libssl/src/crypto/asn1/a_int.c b/src/lib/libssl/src/crypto/asn1/a_int.c index 6c38ace8f9..f41d462ffe 100644 --- a/src/lib/libssl/src/crypto/asn1/a_int.c +++ b/src/lib/libssl/src/crypto/asn1/a_int.c | |||
@@ -65,17 +65,17 @@ ASN1_INTEGER *ASN1_INTEGER_dup(const ASN1_INTEGER *x) | |||
65 | { return M_ASN1_INTEGER_dup(x);} | 65 | { return M_ASN1_INTEGER_dup(x);} |
66 | 66 | ||
67 | int ASN1_INTEGER_cmp(const ASN1_INTEGER *x, const ASN1_INTEGER *y) | 67 | int ASN1_INTEGER_cmp(const ASN1_INTEGER *x, const ASN1_INTEGER *y) |
68 | { | 68 | { |
69 | int neg, ret; | 69 | int neg, ret; |
70 | /* Compare signs */ | 70 | /* Compare signs */ |
71 | neg = x->type & V_ASN1_NEG; | 71 | neg = x->type & V_ASN1_NEG; |
72 | if (neg != (y->type & V_ASN1_NEG)) | 72 | if (neg != (y->type & V_ASN1_NEG)) |
73 | { | 73 | { |
74 | if (neg) | 74 | if (neg) |
75 | return -1; | 75 | return -1; |
76 | else | 76 | else |
77 | return 1; | 77 | return 1; |
78 | } | 78 | } |
79 | 79 | ||
80 | ret = ASN1_STRING_cmp(x, y); | 80 | ret = ASN1_STRING_cmp(x, y); |
81 | 81 | ||
@@ -83,7 +83,7 @@ int ASN1_INTEGER_cmp(const ASN1_INTEGER *x, const ASN1_INTEGER *y) | |||
83 | return -ret; | 83 | return -ret; |
84 | else | 84 | else |
85 | return ret; | 85 | return ret; |
86 | } | 86 | } |
87 | 87 | ||
88 | 88 | ||
89 | /* | 89 | /* |
@@ -112,7 +112,7 @@ int ASN1_INTEGER_cmp(const ASN1_INTEGER *x, const ASN1_INTEGER *y) | |||
112 | */ | 112 | */ |
113 | 113 | ||
114 | int i2c_ASN1_INTEGER(ASN1_INTEGER *a, unsigned char **pp) | 114 | int i2c_ASN1_INTEGER(ASN1_INTEGER *a, unsigned char **pp) |
115 | { | 115 | { |
116 | int pad=0,ret,i,neg; | 116 | int pad=0,ret,i,neg; |
117 | unsigned char *p,*n,pb=0; | 117 | unsigned char *p,*n,pb=0; |
118 | 118 | ||
@@ -121,17 +121,17 @@ int i2c_ASN1_INTEGER(ASN1_INTEGER *a, unsigned char **pp) | |||
121 | if (a->length == 0) | 121 | if (a->length == 0) |
122 | ret=1; | 122 | ret=1; |
123 | else | 123 | else |
124 | { | 124 | { |
125 | ret=a->length; | 125 | ret=a->length; |
126 | i=a->data[0]; | 126 | i=a->data[0]; |
127 | if (!neg && (i > 127)) { | 127 | if (!neg && (i > 127)) { |
128 | pad=1; | 128 | pad=1; |
129 | pb=0; | 129 | pb=0; |
130 | } else if(neg) { | 130 | } else if(neg) { |
131 | if(i>128) { | 131 | if(i>128) { |
132 | pad=1; | 132 | pad=1; |
133 | pb=0xFF; | 133 | pb=0xFF; |
134 | } else if(i == 128) { | 134 | } else if(i == 128) { |
135 | /* | 135 | /* |
136 | * Special case: if any other bytes non zero we pad: | 136 | * Special case: if any other bytes non zero we pad: |
137 | * otherwise we don't. | 137 | * otherwise we don't. |
@@ -140,11 +140,11 @@ int i2c_ASN1_INTEGER(ASN1_INTEGER *a, unsigned char **pp) | |||
140 | pad=1; | 140 | pad=1; |
141 | pb=0xFF; | 141 | pb=0xFF; |
142 | break; | 142 | break; |
143 | } | ||
144 | } | 143 | } |
145 | } | 144 | } |
145 | } | ||
146 | ret+=pad; | 146 | ret+=pad; |
147 | } | 147 | } |
148 | if (pp == NULL) return(ret); | 148 | if (pp == NULL) return(ret); |
149 | p= *pp; | 149 | p= *pp; |
150 | 150 | ||
@@ -161,33 +161,33 @@ int i2c_ASN1_INTEGER(ASN1_INTEGER *a, unsigned char **pp) | |||
161 | *(p--) = 0; | 161 | *(p--) = 0; |
162 | n--; | 162 | n--; |
163 | i--; | 163 | i--; |
164 | } | 164 | } |
165 | /* Complement and increment next octet */ | 165 | /* Complement and increment next octet */ |
166 | *(p--) = ((*(n--)) ^ 0xff) + 1; | 166 | *(p--) = ((*(n--)) ^ 0xff) + 1; |
167 | i--; | 167 | i--; |
168 | /* Complement any octets left */ | 168 | /* Complement any octets left */ |
169 | for(;i > 0; i--) *(p--) = *(n--) ^ 0xff; | 169 | for(;i > 0; i--) *(p--) = *(n--) ^ 0xff; |
170 | } | 170 | } |
171 | 171 | ||
172 | *pp+=ret; | 172 | *pp+=ret; |
173 | return(ret); | 173 | return(ret); |
174 | } | 174 | } |
175 | 175 | ||
176 | /* Convert just ASN1 INTEGER content octets to ASN1_INTEGER structure */ | 176 | /* Convert just ASN1 INTEGER content octets to ASN1_INTEGER structure */ |
177 | 177 | ||
178 | ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **a, const unsigned char **pp, | 178 | ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **a, const unsigned char **pp, |
179 | long len) | 179 | long len) |
180 | { | 180 | { |
181 | ASN1_INTEGER *ret=NULL; | 181 | ASN1_INTEGER *ret=NULL; |
182 | const unsigned char *p, *pend; | 182 | const unsigned char *p, *pend; |
183 | unsigned char *to,*s; | 183 | unsigned char *to,*s; |
184 | int i; | 184 | int i; |
185 | 185 | ||
186 | if ((a == NULL) || ((*a) == NULL)) | 186 | if ((a == NULL) || ((*a) == NULL)) |
187 | { | 187 | { |
188 | if ((ret=M_ASN1_INTEGER_new()) == NULL) return(NULL); | 188 | if ((ret=M_ASN1_INTEGER_new()) == NULL) return(NULL); |
189 | ret->type=V_ASN1_INTEGER; | 189 | ret->type=V_ASN1_INTEGER; |
190 | } | 190 | } |
191 | else | 191 | else |
192 | ret=(*a); | 192 | ret=(*a); |
193 | 193 | ||
@@ -198,23 +198,23 @@ ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **a, const unsigned char **pp, | |||
198 | * signifies a missing NULL parameter. */ | 198 | * signifies a missing NULL parameter. */ |
199 | s=(unsigned char *)malloc((int)len+1); | 199 | s=(unsigned char *)malloc((int)len+1); |
200 | if (s == NULL) | 200 | if (s == NULL) |
201 | { | 201 | { |
202 | i=ERR_R_MALLOC_FAILURE; | 202 | i=ERR_R_MALLOC_FAILURE; |
203 | goto err; | 203 | goto err; |
204 | } | 204 | } |
205 | to=s; | 205 | to=s; |
206 | if(!len) { | 206 | if(!len) { |
207 | /* Strictly speaking this is an illegal INTEGER but we | 207 | /* Strictly speaking this is an illegal INTEGER but we |
208 | * tolerate it. | 208 | * tolerate it. |
209 | */ | 209 | */ |
210 | ret->type=V_ASN1_INTEGER; | 210 | ret->type=V_ASN1_INTEGER; |
211 | } else if (*p & 0x80) /* a negative number */ | 211 | } else if (*p & 0x80) /* a negative number */ |
212 | { | 212 | { |
213 | ret->type=V_ASN1_NEG_INTEGER; | 213 | ret->type=V_ASN1_NEG_INTEGER; |
214 | if ((*p == 0xff) && (len != 1)) { | 214 | if ((*p == 0xff) && (len != 1)) { |
215 | p++; | 215 | p++; |
216 | len--; | 216 | len--; |
217 | } | 217 | } |
218 | i = len; | 218 | i = len; |
219 | p += i - 1; | 219 | p += i - 1; |
220 | to += i - 1; | 220 | to += i - 1; |
@@ -222,7 +222,7 @@ ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **a, const unsigned char **pp, | |||
222 | *(to--) = 0; | 222 | *(to--) = 0; |
223 | i--; | 223 | i--; |
224 | p--; | 224 | p--; |
225 | } | 225 | } |
226 | /* Special case: if all zeros then the number will be of | 226 | /* Special case: if all zeros then the number will be of |
227 | * the form FF followed by n zero bytes: this corresponds to | 227 | * the form FF followed by n zero bytes: this corresponds to |
228 | * 1 followed by n zero bytes. We've already written n zeros | 228 | * 1 followed by n zero bytes. We've already written n zeros |
@@ -234,20 +234,20 @@ ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **a, const unsigned char **pp, | |||
234 | *s = 1; | 234 | *s = 1; |
235 | s[len] = 0; | 235 | s[len] = 0; |
236 | len++; | 236 | len++; |
237 | } else { | 237 | } else { |
238 | *(to--) = (*(p--) ^ 0xff) + 1; | 238 | *(to--) = (*(p--) ^ 0xff) + 1; |
239 | i--; | 239 | i--; |
240 | for(;i > 0; i--) *(to--) = *(p--) ^ 0xff; | 240 | for(;i > 0; i--) *(to--) = *(p--) ^ 0xff; |
241 | } | 241 | } |
242 | } else { | 242 | } else { |
243 | ret->type=V_ASN1_INTEGER; | 243 | ret->type=V_ASN1_INTEGER; |
244 | if ((*p == 0) && (len != 1)) | 244 | if ((*p == 0) && (len != 1)) |
245 | { | 245 | { |
246 | p++; | 246 | p++; |
247 | len--; | 247 | len--; |
248 | } | 248 | } |
249 | memcpy(s,p,(int)len); | 249 | memcpy(s,p,(int)len); |
250 | } | 250 | } |
251 | 251 | ||
252 | if (ret->data != NULL) free(ret->data); | 252 | if (ret->data != NULL) free(ret->data); |
253 | ret->data=s; | 253 | ret->data=s; |
@@ -260,7 +260,7 @@ err: | |||
260 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) | 260 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) |
261 | M_ASN1_INTEGER_free(ret); | 261 | M_ASN1_INTEGER_free(ret); |
262 | return(NULL); | 262 | return(NULL); |
263 | } | 263 | } |
264 | 264 | ||
265 | 265 | ||
266 | /* This is a version of d2i_ASN1_INTEGER that ignores the sign bit of | 266 | /* This is a version of d2i_ASN1_INTEGER that ignores the sign bit of |
@@ -270,7 +270,7 @@ err: | |||
270 | 270 | ||
271 | ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a, const unsigned char **pp, | 271 | ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a, const unsigned char **pp, |
272 | long length) | 272 | long length) |
273 | { | 273 | { |
274 | ASN1_INTEGER *ret=NULL; | 274 | ASN1_INTEGER *ret=NULL; |
275 | const unsigned char *p; | 275 | const unsigned char *p; |
276 | unsigned char *s; | 276 | unsigned char *s; |
@@ -279,45 +279,45 @@ ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a, const unsigned char **pp, | |||
279 | int i; | 279 | int i; |
280 | 280 | ||
281 | if ((a == NULL) || ((*a) == NULL)) | 281 | if ((a == NULL) || ((*a) == NULL)) |
282 | { | 282 | { |
283 | if ((ret=M_ASN1_INTEGER_new()) == NULL) return(NULL); | 283 | if ((ret=M_ASN1_INTEGER_new()) == NULL) return(NULL); |
284 | ret->type=V_ASN1_INTEGER; | 284 | ret->type=V_ASN1_INTEGER; |
285 | } | 285 | } |
286 | else | 286 | else |
287 | ret=(*a); | 287 | ret=(*a); |
288 | 288 | ||
289 | p= *pp; | 289 | p= *pp; |
290 | inf=ASN1_get_object(&p,&len,&tag,&xclass,length); | 290 | inf=ASN1_get_object(&p,&len,&tag,&xclass,length); |
291 | if (inf & 0x80) | 291 | if (inf & 0x80) |
292 | { | 292 | { |
293 | i=ASN1_R_BAD_OBJECT_HEADER; | 293 | i=ASN1_R_BAD_OBJECT_HEADER; |
294 | goto err; | 294 | goto err; |
295 | } | 295 | } |
296 | 296 | ||
297 | if (tag != V_ASN1_INTEGER) | 297 | if (tag != V_ASN1_INTEGER) |
298 | { | 298 | { |
299 | i=ASN1_R_EXPECTING_AN_INTEGER; | 299 | i=ASN1_R_EXPECTING_AN_INTEGER; |
300 | goto err; | 300 | goto err; |
301 | } | 301 | } |
302 | 302 | ||
303 | /* We must malloc stuff, even for 0 bytes otherwise it | 303 | /* We must malloc stuff, even for 0 bytes otherwise it |
304 | * signifies a missing NULL parameter. */ | 304 | * signifies a missing NULL parameter. */ |
305 | s=(unsigned char *)malloc((int)len+1); | 305 | s=(unsigned char *)malloc((int)len+1); |
306 | if (s == NULL) | 306 | if (s == NULL) |
307 | { | 307 | { |
308 | i=ERR_R_MALLOC_FAILURE; | 308 | i=ERR_R_MALLOC_FAILURE; |
309 | goto err; | 309 | goto err; |
310 | } | 310 | } |
311 | ret->type=V_ASN1_INTEGER; | 311 | ret->type=V_ASN1_INTEGER; |
312 | if(len) { | 312 | if(len) { |
313 | if ((*p == 0) && (len != 1)) | 313 | if ((*p == 0) && (len != 1)) |
314 | { | 314 | { |
315 | p++; | 315 | p++; |
316 | len--; | 316 | len--; |
317 | } | 317 | } |
318 | memcpy(s,p,(int)len); | 318 | memcpy(s,p,(int)len); |
319 | p+=len; | 319 | p+=len; |
320 | } | 320 | } |
321 | 321 | ||
322 | if (ret->data != NULL) free(ret->data); | 322 | if (ret->data != NULL) free(ret->data); |
323 | ret->data=s; | 323 | ret->data=s; |
@@ -330,10 +330,10 @@ err: | |||
330 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) | 330 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) |
331 | M_ASN1_INTEGER_free(ret); | 331 | M_ASN1_INTEGER_free(ret); |
332 | return(NULL); | 332 | return(NULL); |
333 | } | 333 | } |
334 | 334 | ||
335 | int ASN1_INTEGER_set(ASN1_INTEGER *a, long v) | 335 | int ASN1_INTEGER_set(ASN1_INTEGER *a, long v) |
336 | { | 336 | { |
337 | int j,k; | 337 | int j,k; |
338 | unsigned int i; | 338 | unsigned int i; |
339 | unsigned char buf[sizeof(long)+1]; | 339 | unsigned char buf[sizeof(long)+1]; |
@@ -341,39 +341,39 @@ int ASN1_INTEGER_set(ASN1_INTEGER *a, long v) | |||
341 | 341 | ||
342 | a->type=V_ASN1_INTEGER; | 342 | a->type=V_ASN1_INTEGER; |
343 | if (a->length < (int)(sizeof(long)+1)) | 343 | if (a->length < (int)(sizeof(long)+1)) |
344 | { | 344 | { |
345 | if (a->data != NULL) | 345 | if (a->data != NULL) |
346 | free(a->data); | 346 | free(a->data); |
347 | if ((a->data=(unsigned char *)malloc(sizeof(long)+1)) != NULL) | 347 | if ((a->data=(unsigned char *)malloc(sizeof(long)+1)) != NULL) |
348 | memset((char *)a->data,0,sizeof(long)+1); | 348 | memset((char *)a->data,0,sizeof(long)+1); |
349 | } | 349 | } |
350 | if (a->data == NULL) | 350 | if (a->data == NULL) |
351 | { | 351 | { |
352 | ASN1err(ASN1_F_ASN1_INTEGER_SET,ERR_R_MALLOC_FAILURE); | 352 | ASN1err(ASN1_F_ASN1_INTEGER_SET,ERR_R_MALLOC_FAILURE); |
353 | return(0); | 353 | return(0); |
354 | } | 354 | } |
355 | d=v; | 355 | d=v; |
356 | if (d < 0) | 356 | if (d < 0) |
357 | { | 357 | { |
358 | d= -d; | 358 | d= -d; |
359 | a->type=V_ASN1_NEG_INTEGER; | 359 | a->type=V_ASN1_NEG_INTEGER; |
360 | } | 360 | } |
361 | 361 | ||
362 | for (i=0; i<sizeof(long); i++) | 362 | for (i=0; i<sizeof(long); i++) |
363 | { | 363 | { |
364 | if (d == 0) break; | 364 | if (d == 0) break; |
365 | buf[i]=(int)d&0xff; | 365 | buf[i]=(int)d&0xff; |
366 | d>>=8; | 366 | d>>=8; |
367 | } | 367 | } |
368 | j=0; | 368 | j=0; |
369 | for (k=i-1; k >=0; k--) | 369 | for (k=i-1; k >=0; k--) |
370 | a->data[j++]=buf[k]; | 370 | a->data[j++]=buf[k]; |
371 | a->length=j; | 371 | a->length=j; |
372 | return(1); | 372 | return(1); |
373 | } | 373 | } |
374 | 374 | ||
375 | long ASN1_INTEGER_get(const ASN1_INTEGER *a) | 375 | long ASN1_INTEGER_get(const ASN1_INTEGER *a) |
376 | { | 376 | { |
377 | int neg=0,i; | 377 | int neg=0,i; |
378 | long r=0; | 378 | long r=0; |
379 | 379 | ||
@@ -385,24 +385,24 @@ long ASN1_INTEGER_get(const ASN1_INTEGER *a) | |||
385 | return -1; | 385 | return -1; |
386 | 386 | ||
387 | if (a->length > (int)sizeof(long)) | 387 | if (a->length > (int)sizeof(long)) |
388 | { | 388 | { |
389 | /* hmm... a bit ugly, return all ones */ | 389 | /* hmm... a bit ugly, return all ones */ |
390 | return -1; | 390 | return -1; |
391 | } | 391 | } |
392 | if (a->data == NULL) | 392 | if (a->data == NULL) |
393 | return 0; | 393 | return 0; |
394 | 394 | ||
395 | for (i=0; i<a->length; i++) | 395 | for (i=0; i<a->length; i++) |
396 | { | 396 | { |
397 | r<<=8; | 397 | r<<=8; |
398 | r|=(unsigned char)a->data[i]; | 398 | r|=(unsigned char)a->data[i]; |
399 | } | 399 | } |
400 | if (neg) r= -r; | 400 | if (neg) r= -r; |
401 | return(r); | 401 | return(r); |
402 | } | 402 | } |
403 | 403 | ||
404 | ASN1_INTEGER *BN_to_ASN1_INTEGER(const BIGNUM *bn, ASN1_INTEGER *ai) | 404 | ASN1_INTEGER *BN_to_ASN1_INTEGER(const BIGNUM *bn, ASN1_INTEGER *ai) |
405 | { | 405 | { |
406 | ASN1_INTEGER *ret; | 406 | ASN1_INTEGER *ret; |
407 | int len,j; | 407 | int len,j; |
408 | 408 | ||
@@ -411,40 +411,40 @@ ASN1_INTEGER *BN_to_ASN1_INTEGER(const BIGNUM *bn, ASN1_INTEGER *ai) | |||
411 | else | 411 | else |
412 | ret=ai; | 412 | ret=ai; |
413 | if (ret == NULL) | 413 | if (ret == NULL) |
414 | { | 414 | { |
415 | ASN1err(ASN1_F_BN_TO_ASN1_INTEGER,ERR_R_NESTED_ASN1_ERROR); | 415 | ASN1err(ASN1_F_BN_TO_ASN1_INTEGER,ERR_R_NESTED_ASN1_ERROR); |
416 | goto err; | 416 | goto err; |
417 | } | 417 | } |
418 | if (BN_is_negative(bn)) | 418 | if (BN_is_negative(bn)) |
419 | ret->type = V_ASN1_NEG_INTEGER; | 419 | ret->type = V_ASN1_NEG_INTEGER; |
420 | else ret->type=V_ASN1_INTEGER; | 420 | else ret->type=V_ASN1_INTEGER; |
421 | j=BN_num_bits(bn); | 421 | j=BN_num_bits(bn); |
422 | len=((j == 0)?0:((j/8)+1)); | 422 | len=((j == 0)?0:((j/8)+1)); |
423 | if (ret->length < len+4) | 423 | if (ret->length < len+4) |
424 | { | 424 | { |
425 | unsigned char *new_data=realloc(ret->data, len+4); | 425 | unsigned char *new_data=realloc(ret->data, len+4); |
426 | if (!new_data) | 426 | if (!new_data) |
427 | { | 427 | { |
428 | ASN1err(ASN1_F_BN_TO_ASN1_INTEGER,ERR_R_MALLOC_FAILURE); | 428 | ASN1err(ASN1_F_BN_TO_ASN1_INTEGER,ERR_R_MALLOC_FAILURE); |
429 | goto err; | 429 | goto err; |
430 | } | ||
431 | ret->data=new_data; | ||
432 | } | 430 | } |
431 | ret->data=new_data; | ||
432 | } | ||
433 | ret->length=BN_bn2bin(bn,ret->data); | 433 | ret->length=BN_bn2bin(bn,ret->data); |
434 | /* Correct zero case */ | 434 | /* Correct zero case */ |
435 | if(!ret->length) | 435 | if(!ret->length) |
436 | { | 436 | { |
437 | ret->data[0] = 0; | 437 | ret->data[0] = 0; |
438 | ret->length = 1; | 438 | ret->length = 1; |
439 | } | 439 | } |
440 | return(ret); | 440 | return(ret); |
441 | err: | 441 | err: |
442 | if (ret != ai) M_ASN1_INTEGER_free(ret); | 442 | if (ret != ai) M_ASN1_INTEGER_free(ret); |
443 | return(NULL); | 443 | return(NULL); |
444 | } | 444 | } |
445 | 445 | ||
446 | BIGNUM *ASN1_INTEGER_to_BN(const ASN1_INTEGER *ai, BIGNUM *bn) | 446 | BIGNUM *ASN1_INTEGER_to_BN(const ASN1_INTEGER *ai, BIGNUM *bn) |
447 | { | 447 | { |
448 | BIGNUM *ret; | 448 | BIGNUM *ret; |
449 | 449 | ||
450 | if ((ret=BN_bin2bn(ai->data,ai->length,bn)) == NULL) | 450 | if ((ret=BN_bin2bn(ai->data,ai->length,bn)) == NULL) |
@@ -452,7 +452,7 @@ BIGNUM *ASN1_INTEGER_to_BN(const ASN1_INTEGER *ai, BIGNUM *bn) | |||
452 | else if(ai->type == V_ASN1_NEG_INTEGER) | 452 | else if(ai->type == V_ASN1_NEG_INTEGER) |
453 | BN_set_negative(ret, 1); | 453 | BN_set_negative(ret, 1); |
454 | return(ret); | 454 | return(ret); |
455 | } | 455 | } |
456 | 456 | ||
457 | IMPLEMENT_STACK_OF(ASN1_INTEGER) | 457 | IMPLEMENT_STACK_OF(ASN1_INTEGER) |
458 | IMPLEMENT_ASN1_SET_OF(ASN1_INTEGER) | 458 | IMPLEMENT_ASN1_SET_OF(ASN1_INTEGER) |
diff --git a/src/lib/libssl/src/crypto/asn1/a_object.c b/src/lib/libssl/src/crypto/asn1/a_object.c index c30f32442d..7e9eeaa2e1 100644 --- a/src/lib/libssl/src/crypto/asn1/a_object.c +++ b/src/lib/libssl/src/crypto/asn1/a_object.c | |||
@@ -65,7 +65,7 @@ | |||
65 | #include <openssl/bn.h> | 65 | #include <openssl/bn.h> |
66 | 66 | ||
67 | int i2d_ASN1_OBJECT(ASN1_OBJECT *a, unsigned char **pp) | 67 | int i2d_ASN1_OBJECT(ASN1_OBJECT *a, unsigned char **pp) |
68 | { | 68 | { |
69 | unsigned char *p; | 69 | unsigned char *p; |
70 | int objsize; | 70 | int objsize; |
71 | 71 | ||
@@ -81,10 +81,10 @@ int i2d_ASN1_OBJECT(ASN1_OBJECT *a, unsigned char **pp) | |||
81 | 81 | ||
82 | *pp=p; | 82 | *pp=p; |
83 | return(objsize); | 83 | return(objsize); |
84 | } | 84 | } |
85 | 85 | ||
86 | int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num) | 86 | int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num) |
87 | { | 87 | { |
88 | int i,first,len=0,c, use_bn; | 88 | int i,first,len=0,c, use_bn; |
89 | char ftmp[24], *tmp = ftmp; | 89 | char ftmp[24], *tmp = ftmp; |
90 | int tmpsize = sizeof ftmp; | 90 | int tmpsize = sizeof ftmp; |
@@ -101,119 +101,119 @@ int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num) | |||
101 | c= *(p++); | 101 | c= *(p++); |
102 | num--; | 102 | num--; |
103 | if ((c >= '0') && (c <= '2')) | 103 | if ((c >= '0') && (c <= '2')) |
104 | { | 104 | { |
105 | first= c-'0'; | 105 | first= c-'0'; |
106 | } | 106 | } |
107 | else | 107 | else |
108 | { | 108 | { |
109 | ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_FIRST_NUM_TOO_LARGE); | 109 | ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_FIRST_NUM_TOO_LARGE); |
110 | goto err; | 110 | goto err; |
111 | } | 111 | } |
112 | 112 | ||
113 | if (num <= 0) | 113 | if (num <= 0) |
114 | { | 114 | { |
115 | ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_MISSING_SECOND_NUMBER); | 115 | ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_MISSING_SECOND_NUMBER); |
116 | goto err; | 116 | goto err; |
117 | } | 117 | } |
118 | c= *(p++); | 118 | c= *(p++); |
119 | num--; | 119 | num--; |
120 | for (;;) | 120 | for (;;) |
121 | { | 121 | { |
122 | if (num <= 0) break; | 122 | if (num <= 0) break; |
123 | if ((c != '.') && (c != ' ')) | 123 | if ((c != '.') && (c != ' ')) |
124 | { | 124 | { |
125 | ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_INVALID_SEPARATOR); | 125 | ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_INVALID_SEPARATOR); |
126 | goto err; | 126 | goto err; |
127 | } | 127 | } |
128 | l=0; | 128 | l=0; |
129 | use_bn = 0; | 129 | use_bn = 0; |
130 | for (;;) | 130 | for (;;) |
131 | { | 131 | { |
132 | if (num <= 0) break; | 132 | if (num <= 0) break; |
133 | num--; | 133 | num--; |
134 | c= *(p++); | 134 | c= *(p++); |
135 | if ((c == ' ') || (c == '.')) | 135 | if ((c == ' ') || (c == '.')) |
136 | break; | 136 | break; |
137 | if ((c < '0') || (c > '9')) | 137 | if ((c < '0') || (c > '9')) |
138 | { | 138 | { |
139 | ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_INVALID_DIGIT); | 139 | ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_INVALID_DIGIT); |
140 | goto err; | 140 | goto err; |
141 | } | 141 | } |
142 | if (!use_bn && l >= ((ULONG_MAX - 80) / 10L)) | 142 | if (!use_bn && l >= ((ULONG_MAX - 80) / 10L)) |
143 | { | 143 | { |
144 | use_bn = 1; | 144 | use_bn = 1; |
145 | if (!bl) | 145 | if (!bl) |
146 | bl = BN_new(); | 146 | bl = BN_new(); |
147 | if (!bl || !BN_set_word(bl, l)) | 147 | if (!bl || !BN_set_word(bl, l)) |
148 | goto err; | 148 | goto err; |
149 | } | 149 | } |
150 | if (use_bn) | 150 | if (use_bn) |
151 | { | 151 | { |
152 | if (!BN_mul_word(bl, 10L) | 152 | if (!BN_mul_word(bl, 10L) |
153 | || !BN_add_word(bl, c-'0')) | 153 | || !BN_add_word(bl, c-'0')) |
154 | goto err; | 154 | goto err; |
155 | } | 155 | } |
156 | else | 156 | else |
157 | l=l*10L+(long)(c-'0'); | 157 | l=l*10L+(long)(c-'0'); |
158 | } | 158 | } |
159 | if (len == 0) | 159 | if (len == 0) |
160 | { | 160 | { |
161 | if ((first < 2) && (l >= 40)) | 161 | if ((first < 2) && (l >= 40)) |
162 | { | 162 | { |
163 | ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_SECOND_NUMBER_TOO_LARGE); | 163 | ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_SECOND_NUMBER_TOO_LARGE); |
164 | goto err; | 164 | goto err; |
165 | } | 165 | } |
166 | if (use_bn) | 166 | if (use_bn) |
167 | { | 167 | { |
168 | if (!BN_add_word(bl, first * 40)) | 168 | if (!BN_add_word(bl, first * 40)) |
169 | goto err; | 169 | goto err; |
170 | } | 170 | } |
171 | else | 171 | else |
172 | l+=(long)first*40; | 172 | l+=(long)first*40; |
173 | } | 173 | } |
174 | i=0; | 174 | i=0; |
175 | if (use_bn) | 175 | if (use_bn) |
176 | { | 176 | { |
177 | int blsize; | 177 | int blsize; |
178 | blsize = BN_num_bits(bl); | 178 | blsize = BN_num_bits(bl); |
179 | blsize = (blsize + 6)/7; | 179 | blsize = (blsize + 6)/7; |
180 | if (blsize > tmpsize) | 180 | if (blsize > tmpsize) |
181 | { | 181 | { |
182 | if (tmp != ftmp) | 182 | if (tmp != ftmp) |
183 | free(tmp); | 183 | free(tmp); |
184 | tmpsize = blsize + 32; | 184 | tmpsize = blsize + 32; |
185 | tmp = malloc(tmpsize); | 185 | tmp = malloc(tmpsize); |
186 | if (!tmp) | 186 | if (!tmp) |
187 | goto err; | 187 | goto err; |
188 | } | 188 | } |
189 | while(blsize--) | 189 | while(blsize--) |
190 | tmp[i++] = (unsigned char)BN_div_word(bl, 0x80L); | 190 | tmp[i++] = (unsigned char)BN_div_word(bl, 0x80L); |
191 | } | 191 | } |
192 | else | 192 | else |
193 | { | 193 | { |
194 | 194 | ||
195 | for (;;) | 195 | for (;;) |
196 | { | 196 | { |
197 | tmp[i++]=(unsigned char)l&0x7f; | 197 | tmp[i++]=(unsigned char)l&0x7f; |
198 | l>>=7L; | 198 | l>>=7L; |
199 | if (l == 0L) break; | 199 | if (l == 0L) break; |
200 | } | ||
201 | |||
202 | } | 200 | } |
201 | |||
202 | } | ||
203 | if (out != NULL) | 203 | if (out != NULL) |
204 | { | 204 | { |
205 | if (len+i > olen) | 205 | if (len+i > olen) |
206 | { | 206 | { |
207 | ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_BUFFER_TOO_SMALL); | 207 | ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_BUFFER_TOO_SMALL); |
208 | goto err; | 208 | goto err; |
209 | } | 209 | } |
210 | while (--i > 0) | 210 | while (--i > 0) |
211 | out[len++]=tmp[i]|0x80; | 211 | out[len++]=tmp[i]|0x80; |
212 | out[len++]=tmp[0]; | 212 | out[len++]=tmp[0]; |
213 | } | 213 | } |
214 | else | 214 | else |
215 | len+=i; | 215 | len+=i; |
216 | } | 216 | } |
217 | if (tmp != ftmp) | 217 | if (tmp != ftmp) |
218 | free(tmp); | 218 | free(tmp); |
219 | if (bl) | 219 | if (bl) |
@@ -225,7 +225,7 @@ err: | |||
225 | if (bl) | 225 | if (bl) |
226 | BN_free(bl); | 226 | BN_free(bl); |
227 | return(0); | 227 | return(0); |
228 | } | 228 | } |
229 | 229 | ||
230 | int i2t_ASN1_OBJECT(char *buf, int buf_len, ASN1_OBJECT *a) | 230 | int i2t_ASN1_OBJECT(char *buf, int buf_len, ASN1_OBJECT *a) |
231 | { | 231 | { |
@@ -233,7 +233,7 @@ int i2t_ASN1_OBJECT(char *buf, int buf_len, ASN1_OBJECT *a) | |||
233 | } | 233 | } |
234 | 234 | ||
235 | int i2a_ASN1_OBJECT(BIO *bp, ASN1_OBJECT *a) | 235 | int i2a_ASN1_OBJECT(BIO *bp, ASN1_OBJECT *a) |
236 | { | 236 | { |
237 | char buf[80], *p = buf; | 237 | char buf[80], *p = buf; |
238 | int i; | 238 | int i; |
239 | 239 | ||
@@ -241,19 +241,19 @@ int i2a_ASN1_OBJECT(BIO *bp, ASN1_OBJECT *a) | |||
241 | return(BIO_write(bp,"NULL",4)); | 241 | return(BIO_write(bp,"NULL",4)); |
242 | i=i2t_ASN1_OBJECT(buf,sizeof buf,a); | 242 | i=i2t_ASN1_OBJECT(buf,sizeof buf,a); |
243 | if (i > (int)(sizeof(buf) - 1)) | 243 | if (i > (int)(sizeof(buf) - 1)) |
244 | { | 244 | { |
245 | p = malloc(i + 1); | 245 | p = malloc(i + 1); |
246 | if (!p) | 246 | if (!p) |
247 | return -1; | 247 | return -1; |
248 | i2t_ASN1_OBJECT(p,i + 1,a); | 248 | i2t_ASN1_OBJECT(p,i + 1,a); |
249 | } | 249 | } |
250 | if (i <= 0) | 250 | if (i <= 0) |
251 | return BIO_write(bp, "<INVALID>", 9); | 251 | return BIO_write(bp, "<INVALID>", 9); |
252 | BIO_write(bp,p,i); | 252 | BIO_write(bp,p,i); |
253 | if (p != buf) | 253 | if (p != buf) |
254 | free(p); | 254 | free(p); |
255 | return(i); | 255 | return(i); |
256 | } | 256 | } |
257 | 257 | ||
258 | ASN1_OBJECT *d2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp, | 258 | ASN1_OBJECT *d2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp, |
259 | long length) | 259 | long length) |
@@ -266,16 +266,16 @@ ASN1_OBJECT *d2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp, | |||
266 | p= *pp; | 266 | p= *pp; |
267 | inf=ASN1_get_object(&p,&len,&tag,&xclass,length); | 267 | inf=ASN1_get_object(&p,&len,&tag,&xclass,length); |
268 | if (inf & 0x80) | 268 | if (inf & 0x80) |
269 | { | 269 | { |
270 | i=ASN1_R_BAD_OBJECT_HEADER; | 270 | i=ASN1_R_BAD_OBJECT_HEADER; |
271 | goto err; | 271 | goto err; |
272 | } | 272 | } |
273 | 273 | ||
274 | if (tag != V_ASN1_OBJECT) | 274 | if (tag != V_ASN1_OBJECT) |
275 | { | 275 | { |
276 | i=ASN1_R_EXPECTING_AN_OBJECT; | 276 | i=ASN1_R_EXPECTING_AN_OBJECT; |
277 | goto err; | 277 | goto err; |
278 | } | 278 | } |
279 | ret = c2i_ASN1_OBJECT(a, &p, len); | 279 | ret = c2i_ASN1_OBJECT(a, &p, len); |
280 | if(ret) *pp = p; | 280 | if(ret) *pp = p; |
281 | return ret; | 281 | return ret; |
@@ -285,7 +285,7 @@ err: | |||
285 | } | 285 | } |
286 | ASN1_OBJECT *c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp, | 286 | ASN1_OBJECT *c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp, |
287 | long len) | 287 | long len) |
288 | { | 288 | { |
289 | ASN1_OBJECT *ret=NULL; | 289 | ASN1_OBJECT *ret=NULL; |
290 | const unsigned char *p; | 290 | const unsigned char *p; |
291 | unsigned char *data; | 291 | unsigned char *data; |
@@ -294,21 +294,21 @@ ASN1_OBJECT *c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp, | |||
294 | * subidentifiers, see: X.690 8.19.2 | 294 | * subidentifiers, see: X.690 8.19.2 |
295 | */ | 295 | */ |
296 | for (i = 0, p = *pp; i < len; i++, p++) | 296 | for (i = 0, p = *pp; i < len; i++, p++) |
297 | { | 297 | { |
298 | if (*p == 0x80 && (!i || !(p[-1] & 0x80))) | 298 | if (*p == 0x80 && (!i || !(p[-1] & 0x80))) |
299 | { | 299 | { |
300 | ASN1err(ASN1_F_C2I_ASN1_OBJECT,ASN1_R_INVALID_OBJECT_ENCODING); | 300 | ASN1err(ASN1_F_C2I_ASN1_OBJECT,ASN1_R_INVALID_OBJECT_ENCODING); |
301 | return NULL; | 301 | return NULL; |
302 | } | ||
303 | } | 302 | } |
303 | } | ||
304 | 304 | ||
305 | /* only the ASN1_OBJECTs from the 'table' will have values | 305 | /* only the ASN1_OBJECTs from the 'table' will have values |
306 | * for ->sn or ->ln */ | 306 | * for ->sn or ->ln */ |
307 | if ((a == NULL) || ((*a) == NULL) || | 307 | if ((a == NULL) || ((*a) == NULL) || |
308 | !((*a)->flags & ASN1_OBJECT_FLAG_DYNAMIC)) | 308 | !((*a)->flags & ASN1_OBJECT_FLAG_DYNAMIC)) |
309 | { | 309 | { |
310 | if ((ret=ASN1_OBJECT_new()) == NULL) return(NULL); | 310 | if ((ret=ASN1_OBJECT_new()) == NULL) return(NULL); |
311 | } | 311 | } |
312 | else ret=(*a); | 312 | else ret=(*a); |
313 | 313 | ||
314 | p= *pp; | 314 | p= *pp; |
@@ -317,14 +317,14 @@ ASN1_OBJECT *c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp, | |||
317 | ret->data = NULL; | 317 | ret->data = NULL; |
318 | /* once detached we can change it */ | 318 | /* once detached we can change it */ |
319 | if ((data == NULL) || (ret->length < len)) | 319 | if ((data == NULL) || (ret->length < len)) |
320 | { | 320 | { |
321 | ret->length=0; | 321 | ret->length=0; |
322 | if (data != NULL) free(data); | 322 | if (data != NULL) free(data); |
323 | data=(unsigned char *)malloc(len ? (int)len : 1); | 323 | data=(unsigned char *)malloc(len ? (int)len : 1); |
324 | if (data == NULL) | 324 | if (data == NULL) |
325 | { i=ERR_R_MALLOC_FAILURE; goto err; } | 325 | { i=ERR_R_MALLOC_FAILURE; goto err; } |
326 | ret->flags|=ASN1_OBJECT_FLAG_DYNAMIC_DATA; | 326 | ret->flags|=ASN1_OBJECT_FLAG_DYNAMIC_DATA; |
327 | } | 327 | } |
328 | memcpy(data,p,(int)len); | 328 | memcpy(data,p,(int)len); |
329 | /* reattach data to object, after which it remains const */ | 329 | /* reattach data to object, after which it remains const */ |
330 | ret->data =data; | 330 | ret->data =data; |
@@ -342,18 +342,18 @@ err: | |||
342 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) | 342 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) |
343 | ASN1_OBJECT_free(ret); | 343 | ASN1_OBJECT_free(ret); |
344 | return(NULL); | 344 | return(NULL); |
345 | } | 345 | } |
346 | 346 | ||
347 | ASN1_OBJECT *ASN1_OBJECT_new(void) | 347 | ASN1_OBJECT *ASN1_OBJECT_new(void) |
348 | { | 348 | { |
349 | ASN1_OBJECT *ret; | 349 | ASN1_OBJECT *ret; |
350 | 350 | ||
351 | ret=(ASN1_OBJECT *)malloc(sizeof(ASN1_OBJECT)); | 351 | ret=(ASN1_OBJECT *)malloc(sizeof(ASN1_OBJECT)); |
352 | if (ret == NULL) | 352 | if (ret == NULL) |
353 | { | 353 | { |
354 | ASN1err(ASN1_F_ASN1_OBJECT_NEW,ERR_R_MALLOC_FAILURE); | 354 | ASN1err(ASN1_F_ASN1_OBJECT_NEW,ERR_R_MALLOC_FAILURE); |
355 | return(NULL); | 355 | return(NULL); |
356 | } | 356 | } |
357 | ret->length=0; | 357 | ret->length=0; |
358 | ret->data=NULL; | 358 | ret->data=NULL; |
359 | ret->nid=0; | 359 | ret->nid=0; |
@@ -361,32 +361,32 @@ ASN1_OBJECT *ASN1_OBJECT_new(void) | |||
361 | ret->ln=NULL; | 361 | ret->ln=NULL; |
362 | ret->flags=ASN1_OBJECT_FLAG_DYNAMIC; | 362 | ret->flags=ASN1_OBJECT_FLAG_DYNAMIC; |
363 | return(ret); | 363 | return(ret); |
364 | } | 364 | } |
365 | 365 | ||
366 | void ASN1_OBJECT_free(ASN1_OBJECT *a) | 366 | void ASN1_OBJECT_free(ASN1_OBJECT *a) |
367 | { | 367 | { |
368 | if (a == NULL) return; | 368 | if (a == NULL) return; |
369 | if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_STRINGS) | 369 | if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_STRINGS) |
370 | { | 370 | { |
371 | #ifndef CONST_STRICT /* disable purely for compile-time strict const checking. Doing this on a "real" compile will cause memory leaks */ | 371 | #ifndef CONST_STRICT /* disable purely for compile-time strict const checking. Doing this on a "real" compile will cause memory leaks */ |
372 | if (a->sn != NULL) free((void *)a->sn); | 372 | if (a->sn != NULL) free((void *)a->sn); |
373 | if (a->ln != NULL) free((void *)a->ln); | 373 | if (a->ln != NULL) free((void *)a->ln); |
374 | #endif | 374 | #endif |
375 | a->sn=a->ln=NULL; | 375 | a->sn=a->ln=NULL; |
376 | } | 376 | } |
377 | if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_DATA) | 377 | if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_DATA) |
378 | { | 378 | { |
379 | if (a->data != NULL) free((void *)a->data); | 379 | if (a->data != NULL) free((void *)a->data); |
380 | a->data=NULL; | 380 | a->data=NULL; |
381 | a->length=0; | 381 | a->length=0; |
382 | } | 382 | } |
383 | if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC) | 383 | if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC) |
384 | free(a); | 384 | free(a); |
385 | } | 385 | } |
386 | 386 | ||
387 | ASN1_OBJECT *ASN1_OBJECT_create(int nid, unsigned char *data, int len, | 387 | ASN1_OBJECT *ASN1_OBJECT_create(int nid, unsigned char *data, int len, |
388 | const char *sn, const char *ln) | 388 | const char *sn, const char *ln) |
389 | { | 389 | { |
390 | ASN1_OBJECT o; | 390 | ASN1_OBJECT o; |
391 | 391 | ||
392 | o.sn=sn; | 392 | o.sn=sn; |
@@ -397,7 +397,7 @@ ASN1_OBJECT *ASN1_OBJECT_create(int nid, unsigned char *data, int len, | |||
397 | o.flags=ASN1_OBJECT_FLAG_DYNAMIC|ASN1_OBJECT_FLAG_DYNAMIC_STRINGS| | 397 | o.flags=ASN1_OBJECT_FLAG_DYNAMIC|ASN1_OBJECT_FLAG_DYNAMIC_STRINGS| |
398 | ASN1_OBJECT_FLAG_DYNAMIC_DATA; | 398 | ASN1_OBJECT_FLAG_DYNAMIC_DATA; |
399 | return(OBJ_dup(&o)); | 399 | return(OBJ_dup(&o)); |
400 | } | 400 | } |
401 | 401 | ||
402 | IMPLEMENT_STACK_OF(ASN1_OBJECT) | 402 | IMPLEMENT_STACK_OF(ASN1_OBJECT) |
403 | IMPLEMENT_ASN1_SET_OF(ASN1_OBJECT) | 403 | IMPLEMENT_ASN1_SET_OF(ASN1_OBJECT) |
diff --git a/src/lib/libssl/src/crypto/asn1/a_print.c b/src/lib/libssl/src/crypto/asn1/a_print.c index 9eec5034e1..cfd0452f13 100644 --- a/src/lib/libssl/src/crypto/asn1/a_print.c +++ b/src/lib/libssl/src/crypto/asn1/a_print.c | |||
@@ -61,7 +61,7 @@ | |||
61 | #include <openssl/asn1.h> | 61 | #include <openssl/asn1.h> |
62 | 62 | ||
63 | int ASN1_PRINTABLE_type(const unsigned char *s, int len) | 63 | int ASN1_PRINTABLE_type(const unsigned char *s, int len) |
64 | { | 64 | { |
65 | int c; | 65 | int c; |
66 | int ia5=0; | 66 | int ia5=0; |
67 | int t61=0; | 67 | int t61=0; |
@@ -70,7 +70,7 @@ int ASN1_PRINTABLE_type(const unsigned char *s, int len) | |||
70 | if (s == NULL) return(V_ASN1_PRINTABLESTRING); | 70 | if (s == NULL) return(V_ASN1_PRINTABLESTRING); |
71 | 71 | ||
72 | while ((*s) && (len-- != 0)) | 72 | while ((*s) && (len-- != 0)) |
73 | { | 73 | { |
74 | c= *(s++); | 74 | c= *(s++); |
75 | if (!( ((c >= 'a') && (c <= 'z')) || | 75 | if (!( ((c >= 'a') && (c <= 'z')) || |
76 | ((c >= 'A') && (c <= 'Z')) || | 76 | ((c >= 'A') && (c <= 'Z')) || |
@@ -85,14 +85,14 @@ int ASN1_PRINTABLE_type(const unsigned char *s, int len) | |||
85 | ia5=1; | 85 | ia5=1; |
86 | if (c&0x80) | 86 | if (c&0x80) |
87 | t61=1; | 87 | t61=1; |
88 | } | 88 | } |
89 | if (t61) return(V_ASN1_T61STRING); | 89 | if (t61) return(V_ASN1_T61STRING); |
90 | if (ia5) return(V_ASN1_IA5STRING); | 90 | if (ia5) return(V_ASN1_IA5STRING); |
91 | return(V_ASN1_PRINTABLESTRING); | 91 | return(V_ASN1_PRINTABLESTRING); |
92 | } | 92 | } |
93 | 93 | ||
94 | int ASN1_UNIVERSALSTRING_to_string(ASN1_UNIVERSALSTRING *s) | 94 | int ASN1_UNIVERSALSTRING_to_string(ASN1_UNIVERSALSTRING *s) |
95 | { | 95 | { |
96 | int i; | 96 | int i; |
97 | unsigned char *p; | 97 | unsigned char *p; |
98 | 98 | ||
@@ -100,20 +100,20 @@ int ASN1_UNIVERSALSTRING_to_string(ASN1_UNIVERSALSTRING *s) | |||
100 | if ((s->length%4) != 0) return(0); | 100 | if ((s->length%4) != 0) return(0); |
101 | p=s->data; | 101 | p=s->data; |
102 | for (i=0; i<s->length; i+=4) | 102 | for (i=0; i<s->length; i+=4) |
103 | { | 103 | { |
104 | if ((p[0] != '\0') || (p[1] != '\0') || (p[2] != '\0')) | 104 | if ((p[0] != '\0') || (p[1] != '\0') || (p[2] != '\0')) |
105 | break; | 105 | break; |
106 | else | 106 | else |
107 | p+=4; | 107 | p+=4; |
108 | } | 108 | } |
109 | if (i < s->length) return(0); | 109 | if (i < s->length) return(0); |
110 | p=s->data; | 110 | p=s->data; |
111 | for (i=3; i<s->length; i+=4) | 111 | for (i=3; i<s->length; i+=4) |
112 | { | 112 | { |
113 | *(p++)=s->data[i]; | 113 | *(p++)=s->data[i]; |
114 | } | 114 | } |
115 | *(p)='\0'; | 115 | *(p)='\0'; |
116 | s->length/=4; | 116 | s->length/=4; |
117 | s->type=ASN1_PRINTABLE_type(s->data,s->length); | 117 | s->type=ASN1_PRINTABLE_type(s->data,s->length); |
118 | return(1); | 118 | return(1); |
119 | } | 119 | } |
diff --git a/src/lib/libssl/src/crypto/asn1/a_sign.c b/src/lib/libssl/src/crypto/asn1/a_sign.c index 0433b49a64..349422fe9a 100644 --- a/src/lib/libssl/src/crypto/asn1/a_sign.c +++ b/src/lib/libssl/src/crypto/asn1/a_sign.c | |||
@@ -128,22 +128,22 @@ | |||
128 | int ASN1_item_sign(const ASN1_ITEM *it, X509_ALGOR *algor1, X509_ALGOR *algor2, | 128 | int ASN1_item_sign(const ASN1_ITEM *it, X509_ALGOR *algor1, X509_ALGOR *algor2, |
129 | ASN1_BIT_STRING *signature, void *asn, EVP_PKEY *pkey, | 129 | ASN1_BIT_STRING *signature, void *asn, EVP_PKEY *pkey, |
130 | const EVP_MD *type) | 130 | const EVP_MD *type) |
131 | { | 131 | { |
132 | EVP_MD_CTX ctx; | 132 | EVP_MD_CTX ctx; |
133 | EVP_MD_CTX_init(&ctx); | 133 | EVP_MD_CTX_init(&ctx); |
134 | if (!EVP_DigestSignInit(&ctx, NULL, type, NULL, pkey)) | 134 | if (!EVP_DigestSignInit(&ctx, NULL, type, NULL, pkey)) |
135 | { | 135 | { |
136 | EVP_MD_CTX_cleanup(&ctx); | 136 | EVP_MD_CTX_cleanup(&ctx); |
137 | return 0; | 137 | return 0; |
138 | } | ||
139 | return ASN1_item_sign_ctx(it, algor1, algor2, signature, asn, &ctx); | ||
140 | } | 138 | } |
139 | return ASN1_item_sign_ctx(it, algor1, algor2, signature, asn, &ctx); | ||
140 | } | ||
141 | 141 | ||
142 | 142 | ||
143 | int ASN1_item_sign_ctx(const ASN1_ITEM *it, | 143 | int ASN1_item_sign_ctx(const ASN1_ITEM *it, |
144 | X509_ALGOR *algor1, X509_ALGOR *algor2, | 144 | X509_ALGOR *algor1, X509_ALGOR *algor2, |
145 | ASN1_BIT_STRING *signature, void *asn, EVP_MD_CTX *ctx) | 145 | ASN1_BIT_STRING *signature, void *asn, EVP_MD_CTX *ctx) |
146 | { | 146 | { |
147 | const EVP_MD *type; | 147 | const EVP_MD *type; |
148 | EVP_PKEY *pkey; | 148 | EVP_PKEY *pkey; |
149 | unsigned char *buf_in=NULL,*buf_out=NULL; | 149 | unsigned char *buf_in=NULL,*buf_out=NULL; |
@@ -155,13 +155,13 @@ int ASN1_item_sign_ctx(const ASN1_ITEM *it, | |||
155 | pkey = EVP_PKEY_CTX_get0_pkey(ctx->pctx); | 155 | pkey = EVP_PKEY_CTX_get0_pkey(ctx->pctx); |
156 | 156 | ||
157 | if (!type || !pkey) | 157 | if (!type || !pkey) |
158 | { | 158 | { |
159 | ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX, ASN1_R_CONTEXT_NOT_INITIALISED); | 159 | ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX, ASN1_R_CONTEXT_NOT_INITIALISED); |
160 | return 0; | 160 | return 0; |
161 | } | 161 | } |
162 | 162 | ||
163 | if (pkey->ameth->item_sign) | 163 | if (pkey->ameth->item_sign) |
164 | { | 164 | { |
165 | rv = pkey->ameth->item_sign(ctx, it, asn, algor1, algor2, | 165 | rv = pkey->ameth->item_sign(ctx, it, asn, algor1, algor2, |
166 | signature); | 166 | signature); |
167 | if (rv == 1) | 167 | if (rv == 1) |
@@ -176,24 +176,24 @@ int ASN1_item_sign_ctx(const ASN1_ITEM *it, | |||
176 | ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX, ERR_R_EVP_LIB); | 176 | ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX, ERR_R_EVP_LIB); |
177 | if (rv <= 1) | 177 | if (rv <= 1) |
178 | goto err; | 178 | goto err; |
179 | } | 179 | } |
180 | else | 180 | else |
181 | rv = 2; | 181 | rv = 2; |
182 | 182 | ||
183 | if (rv == 2) | 183 | if (rv == 2) |
184 | { | 184 | { |
185 | if (type->flags & EVP_MD_FLAG_PKEY_METHOD_SIGNATURE) | 185 | if (type->flags & EVP_MD_FLAG_PKEY_METHOD_SIGNATURE) |
186 | { | 186 | { |
187 | if (!pkey->ameth || | 187 | if (!pkey->ameth || |
188 | !OBJ_find_sigid_by_algs(&signid, | 188 | !OBJ_find_sigid_by_algs(&signid, |
189 | EVP_MD_nid(type), | 189 | EVP_MD_nid(type), |
190 | pkey->ameth->pkey_id)) | 190 | pkey->ameth->pkey_id)) |
191 | { | 191 | { |
192 | ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX, | 192 | ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX, |
193 | ASN1_R_DIGEST_AND_KEY_TYPE_NOT_SUPPORTED); | 193 | ASN1_R_DIGEST_AND_KEY_TYPE_NOT_SUPPORTED); |
194 | return 0; | 194 | return 0; |
195 | } | ||
196 | } | 195 | } |
196 | } | ||
197 | else | 197 | else |
198 | signid = type->pkey_type; | 198 | signid = type->pkey_type; |
199 | 199 | ||
@@ -207,25 +207,25 @@ int ASN1_item_sign_ctx(const ASN1_ITEM *it, | |||
207 | if (algor2) | 207 | if (algor2) |
208 | X509_ALGOR_set0(algor2, OBJ_nid2obj(signid), paramtype, NULL); | 208 | X509_ALGOR_set0(algor2, OBJ_nid2obj(signid), paramtype, NULL); |
209 | 209 | ||
210 | } | 210 | } |
211 | 211 | ||
212 | inl=ASN1_item_i2d(asn,&buf_in, it); | 212 | inl=ASN1_item_i2d(asn,&buf_in, it); |
213 | outll=outl=EVP_PKEY_size(pkey); | 213 | outll=outl=EVP_PKEY_size(pkey); |
214 | buf_out=malloc((unsigned int)outl); | 214 | buf_out=malloc((unsigned int)outl); |
215 | if ((buf_in == NULL) || (buf_out == NULL)) | 215 | if ((buf_in == NULL) || (buf_out == NULL)) |
216 | { | 216 | { |
217 | outl=0; | 217 | outl=0; |
218 | ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX,ERR_R_MALLOC_FAILURE); | 218 | ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX,ERR_R_MALLOC_FAILURE); |
219 | goto err; | 219 | goto err; |
220 | } | 220 | } |
221 | 221 | ||
222 | if (!EVP_DigestSignUpdate(ctx, buf_in, inl) | 222 | if (!EVP_DigestSignUpdate(ctx, buf_in, inl) |
223 | || !EVP_DigestSignFinal(ctx, buf_out, &outl)) | 223 | || !EVP_DigestSignFinal(ctx, buf_out, &outl)) |
224 | { | 224 | { |
225 | outl=0; | 225 | outl=0; |
226 | ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX,ERR_R_EVP_LIB); | 226 | ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX,ERR_R_EVP_LIB); |
227 | goto err; | 227 | goto err; |
228 | } | 228 | } |
229 | if (signature->data != NULL) free(signature->data); | 229 | if (signature->data != NULL) free(signature->data); |
230 | signature->data=buf_out; | 230 | signature->data=buf_out; |
231 | buf_out=NULL; | 231 | buf_out=NULL; |
@@ -238,8 +238,8 @@ int ASN1_item_sign_ctx(const ASN1_ITEM *it, | |||
238 | err: | 238 | err: |
239 | EVP_MD_CTX_cleanup(ctx); | 239 | EVP_MD_CTX_cleanup(ctx); |
240 | if (buf_in != NULL) | 240 | if (buf_in != NULL) |
241 | { OPENSSL_cleanse((char *)buf_in,(unsigned int)inl); free(buf_in); } | 241 | { OPENSSL_cleanse((char *)buf_in,(unsigned int)inl); free(buf_in); } |
242 | if (buf_out != NULL) | 242 | if (buf_out != NULL) |
243 | { OPENSSL_cleanse((char *)buf_out,outll); free(buf_out); } | 243 | { OPENSSL_cleanse((char *)buf_out,outll); free(buf_out); } |
244 | return(outl); | 244 | return(outl); |
245 | } | 245 | } |
diff --git a/src/lib/libssl/src/crypto/asn1/a_time.c b/src/lib/libssl/src/crypto/asn1/a_time.c index 4ade88f065..3461660b5f 100644 --- a/src/lib/libssl/src/crypto/asn1/a_time.c +++ b/src/lib/libssl/src/crypto/asn1/a_time.c | |||
@@ -73,55 +73,55 @@ IMPLEMENT_ASN1_FUNCTIONS(ASN1_TIME) | |||
73 | 73 | ||
74 | #if 0 | 74 | #if 0 |
75 | int i2d_ASN1_TIME(ASN1_TIME *a, unsigned char **pp) | 75 | int i2d_ASN1_TIME(ASN1_TIME *a, unsigned char **pp) |
76 | { | 76 | { |
77 | if(a->type == V_ASN1_UTCTIME || a->type == V_ASN1_GENERALIZEDTIME) | 77 | if(a->type == V_ASN1_UTCTIME || a->type == V_ASN1_GENERALIZEDTIME) |
78 | return(i2d_ASN1_bytes((ASN1_STRING *)a,pp, | 78 | return(i2d_ASN1_bytes((ASN1_STRING *)a,pp, |
79 | a->type ,V_ASN1_UNIVERSAL)); | 79 | a->type ,V_ASN1_UNIVERSAL)); |
80 | ASN1err(ASN1_F_I2D_ASN1_TIME,ASN1_R_EXPECTING_A_TIME); | 80 | ASN1err(ASN1_F_I2D_ASN1_TIME,ASN1_R_EXPECTING_A_TIME); |
81 | return -1; | 81 | return -1; |
82 | } | 82 | } |
83 | #endif | 83 | #endif |
84 | 84 | ||
85 | 85 | ||
86 | ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s, time_t t) | 86 | ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s, time_t t) |
87 | { | 87 | { |
88 | return ASN1_TIME_adj(s, t, 0, 0); | 88 | return ASN1_TIME_adj(s, t, 0, 0); |
89 | } | 89 | } |
90 | 90 | ||
91 | ASN1_TIME *ASN1_TIME_adj(ASN1_TIME *s, time_t t, | 91 | ASN1_TIME *ASN1_TIME_adj(ASN1_TIME *s, time_t t, |
92 | int offset_day, long offset_sec) | 92 | int offset_day, long offset_sec) |
93 | { | 93 | { |
94 | struct tm *ts; | 94 | struct tm *ts; |
95 | struct tm data; | 95 | struct tm data; |
96 | 96 | ||
97 | ts=OPENSSL_gmtime(&t,&data); | 97 | ts=OPENSSL_gmtime(&t,&data); |
98 | if (ts == NULL) | 98 | if (ts == NULL) |
99 | { | 99 | { |
100 | ASN1err(ASN1_F_ASN1_TIME_ADJ, ASN1_R_ERROR_GETTING_TIME); | 100 | ASN1err(ASN1_F_ASN1_TIME_ADJ, ASN1_R_ERROR_GETTING_TIME); |
101 | return NULL; | 101 | return NULL; |
102 | } | 102 | } |
103 | if (offset_day || offset_sec) | 103 | if (offset_day || offset_sec) |
104 | { | 104 | { |
105 | if (!OPENSSL_gmtime_adj(ts, offset_day, offset_sec)) | 105 | if (!OPENSSL_gmtime_adj(ts, offset_day, offset_sec)) |
106 | return NULL; | 106 | return NULL; |
107 | } | 107 | } |
108 | if((ts->tm_year >= 50) && (ts->tm_year < 150)) | 108 | if((ts->tm_year >= 50) && (ts->tm_year < 150)) |
109 | return ASN1_UTCTIME_adj(s, t, offset_day, offset_sec); | 109 | return ASN1_UTCTIME_adj(s, t, offset_day, offset_sec); |
110 | return ASN1_GENERALIZEDTIME_adj(s, t, offset_day, offset_sec); | 110 | return ASN1_GENERALIZEDTIME_adj(s, t, offset_day, offset_sec); |
111 | } | 111 | } |
112 | 112 | ||
113 | int ASN1_TIME_check(ASN1_TIME *t) | 113 | int ASN1_TIME_check(ASN1_TIME *t) |
114 | { | 114 | { |
115 | if (t->type == V_ASN1_GENERALIZEDTIME) | 115 | if (t->type == V_ASN1_GENERALIZEDTIME) |
116 | return ASN1_GENERALIZEDTIME_check(t); | 116 | return ASN1_GENERALIZEDTIME_check(t); |
117 | else if (t->type == V_ASN1_UTCTIME) | 117 | else if (t->type == V_ASN1_UTCTIME) |
118 | return ASN1_UTCTIME_check(t); | 118 | return ASN1_UTCTIME_check(t); |
119 | return 0; | 119 | return 0; |
120 | } | 120 | } |
121 | 121 | ||
122 | /* Convert an ASN1_TIME structure to GeneralizedTime */ | 122 | /* Convert an ASN1_TIME structure to GeneralizedTime */ |
123 | ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(ASN1_TIME *t, ASN1_GENERALIZEDTIME **out) | 123 | ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(ASN1_TIME *t, ASN1_GENERALIZEDTIME **out) |
124 | { | 124 | { |
125 | ASN1_GENERALIZEDTIME *ret; | 125 | ASN1_GENERALIZEDTIME *ret; |
126 | char *str; | 126 | char *str; |
127 | int newlen; | 127 | int newlen; |
@@ -129,20 +129,20 @@ ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(ASN1_TIME *t, ASN1_GENERALIZE | |||
129 | if (!ASN1_TIME_check(t)) return NULL; | 129 | if (!ASN1_TIME_check(t)) return NULL; |
130 | 130 | ||
131 | if (!out || !*out) | 131 | if (!out || !*out) |
132 | { | 132 | { |
133 | if (!(ret = ASN1_GENERALIZEDTIME_new ())) | 133 | if (!(ret = ASN1_GENERALIZEDTIME_new ())) |
134 | return NULL; | 134 | return NULL; |
135 | if (out) *out = ret; | 135 | if (out) *out = ret; |
136 | } | 136 | } |
137 | else ret = *out; | 137 | else ret = *out; |
138 | 138 | ||
139 | /* If already GeneralizedTime just copy across */ | 139 | /* If already GeneralizedTime just copy across */ |
140 | if (t->type == V_ASN1_GENERALIZEDTIME) | 140 | if (t->type == V_ASN1_GENERALIZEDTIME) |
141 | { | 141 | { |
142 | if(!ASN1_STRING_set(ret, t->data, t->length)) | 142 | if(!ASN1_STRING_set(ret, t->data, t->length)) |
143 | return NULL; | 143 | return NULL; |
144 | return ret; | 144 | return ret; |
145 | } | 145 | } |
146 | 146 | ||
147 | /* grow the string */ | 147 | /* grow the string */ |
148 | if (!ASN1_STRING_set(ret, NULL, t->length + 2)) | 148 | if (!ASN1_STRING_set(ret, NULL, t->length + 2)) |
@@ -157,10 +157,10 @@ ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(ASN1_TIME *t, ASN1_GENERALIZE | |||
157 | BUF_strlcat(str, (char *)t->data, newlen); | 157 | BUF_strlcat(str, (char *)t->data, newlen); |
158 | 158 | ||
159 | return ret; | 159 | return ret; |
160 | } | 160 | } |
161 | 161 | ||
162 | int ASN1_TIME_set_string(ASN1_TIME *s, const char *str) | 162 | int ASN1_TIME_set_string(ASN1_TIME *s, const char *str) |
163 | { | 163 | { |
164 | ASN1_TIME t; | 164 | ASN1_TIME t; |
165 | 165 | ||
166 | t.length = strlen(str); | 166 | t.length = strlen(str); |
@@ -170,14 +170,14 @@ int ASN1_TIME_set_string(ASN1_TIME *s, const char *str) | |||
170 | t.type = V_ASN1_UTCTIME; | 170 | t.type = V_ASN1_UTCTIME; |
171 | 171 | ||
172 | if (!ASN1_TIME_check(&t)) | 172 | if (!ASN1_TIME_check(&t)) |
173 | { | 173 | { |
174 | t.type = V_ASN1_GENERALIZEDTIME; | 174 | t.type = V_ASN1_GENERALIZEDTIME; |
175 | if (!ASN1_TIME_check(&t)) | 175 | if (!ASN1_TIME_check(&t)) |
176 | return 0; | 176 | return 0; |
177 | } | 177 | } |
178 | 178 | ||
179 | if (s && !ASN1_STRING_copy((ASN1_STRING *)s, (ASN1_STRING *)&t)) | 179 | if (s && !ASN1_STRING_copy((ASN1_STRING *)s, (ASN1_STRING *)&t)) |
180 | return 0; | 180 | return 0; |
181 | 181 | ||
182 | return 1; | 182 | return 1; |
183 | } | 183 | } |
diff --git a/src/lib/libssl/src/crypto/asn1/a_type.c b/src/lib/libssl/src/crypto/asn1/a_type.c index a45d2f9d12..c790d74d60 100644 --- a/src/lib/libssl/src/crypto/asn1/a_type.c +++ b/src/lib/libssl/src/crypto/asn1/a_type.c | |||
@@ -62,65 +62,65 @@ | |||
62 | #include <openssl/objects.h> | 62 | #include <openssl/objects.h> |
63 | 63 | ||
64 | int ASN1_TYPE_get(ASN1_TYPE *a) | 64 | int ASN1_TYPE_get(ASN1_TYPE *a) |
65 | { | 65 | { |
66 | if ((a->value.ptr != NULL) || (a->type == V_ASN1_NULL)) | 66 | if ((a->value.ptr != NULL) || (a->type == V_ASN1_NULL)) |
67 | return(a->type); | 67 | return(a->type); |
68 | else | 68 | else |
69 | return(0); | 69 | return(0); |
70 | } | 70 | } |
71 | 71 | ||
72 | void ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value) | 72 | void ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value) |
73 | { | 73 | { |
74 | if (a->value.ptr != NULL) | 74 | if (a->value.ptr != NULL) |
75 | { | 75 | { |
76 | ASN1_TYPE **tmp_a = &a; | 76 | ASN1_TYPE **tmp_a = &a; |
77 | ASN1_primitive_free((ASN1_VALUE **)tmp_a, NULL); | 77 | ASN1_primitive_free((ASN1_VALUE **)tmp_a, NULL); |
78 | } | 78 | } |
79 | a->type=type; | 79 | a->type=type; |
80 | if (type == V_ASN1_BOOLEAN) | 80 | if (type == V_ASN1_BOOLEAN) |
81 | a->value.boolean = value ? 0xff : 0; | 81 | a->value.boolean = value ? 0xff : 0; |
82 | else | 82 | else |
83 | a->value.ptr=value; | 83 | a->value.ptr=value; |
84 | } | 84 | } |
85 | 85 | ||
86 | int ASN1_TYPE_set1(ASN1_TYPE *a, int type, const void *value) | 86 | int ASN1_TYPE_set1(ASN1_TYPE *a, int type, const void *value) |
87 | { | 87 | { |
88 | if (!value || (type == V_ASN1_BOOLEAN)) | 88 | if (!value || (type == V_ASN1_BOOLEAN)) |
89 | { | 89 | { |
90 | void *p = (void *)value; | 90 | void *p = (void *)value; |
91 | ASN1_TYPE_set(a, type, p); | 91 | ASN1_TYPE_set(a, type, p); |
92 | } | 92 | } |
93 | else if (type == V_ASN1_OBJECT) | 93 | else if (type == V_ASN1_OBJECT) |
94 | { | 94 | { |
95 | ASN1_OBJECT *odup; | 95 | ASN1_OBJECT *odup; |
96 | odup = OBJ_dup(value); | 96 | odup = OBJ_dup(value); |
97 | if (!odup) | 97 | if (!odup) |
98 | return 0; | 98 | return 0; |
99 | ASN1_TYPE_set(a, type, odup); | 99 | ASN1_TYPE_set(a, type, odup); |
100 | } | 100 | } |
101 | else | 101 | else |
102 | { | 102 | { |
103 | ASN1_STRING *sdup; | 103 | ASN1_STRING *sdup; |
104 | sdup = ASN1_STRING_dup(value); | 104 | sdup = ASN1_STRING_dup(value); |
105 | if (!sdup) | 105 | if (!sdup) |
106 | return 0; | 106 | return 0; |
107 | ASN1_TYPE_set(a, type, sdup); | 107 | ASN1_TYPE_set(a, type, sdup); |
108 | } | ||
109 | return 1; | ||
110 | } | 108 | } |
109 | return 1; | ||
110 | } | ||
111 | 111 | ||
112 | IMPLEMENT_STACK_OF(ASN1_TYPE) | 112 | IMPLEMENT_STACK_OF(ASN1_TYPE) |
113 | IMPLEMENT_ASN1_SET_OF(ASN1_TYPE) | 113 | IMPLEMENT_ASN1_SET_OF(ASN1_TYPE) |
114 | 114 | ||
115 | /* Returns 0 if they are equal, != 0 otherwise. */ | 115 | /* Returns 0 if they are equal, != 0 otherwise. */ |
116 | int ASN1_TYPE_cmp(ASN1_TYPE *a, ASN1_TYPE *b) | 116 | int ASN1_TYPE_cmp(ASN1_TYPE *a, ASN1_TYPE *b) |
117 | { | 117 | { |
118 | int result = -1; | 118 | int result = -1; |
119 | 119 | ||
120 | if (!a || !b || a->type != b->type) return -1; | 120 | if (!a || !b || a->type != b->type) return -1; |
121 | 121 | ||
122 | switch (a->type) | 122 | switch (a->type) |
123 | { | 123 | { |
124 | case V_ASN1_OBJECT: | 124 | case V_ASN1_OBJECT: |
125 | result = OBJ_cmp(a->value.object, b->value.object); | 125 | result = OBJ_cmp(a->value.object, b->value.object); |
126 | break; | 126 | break; |
@@ -153,7 +153,7 @@ int ASN1_TYPE_cmp(ASN1_TYPE *a, ASN1_TYPE *b) | |||
153 | result = ASN1_STRING_cmp((ASN1_STRING *) a->value.ptr, | 153 | result = ASN1_STRING_cmp((ASN1_STRING *) a->value.ptr, |
154 | (ASN1_STRING *) b->value.ptr); | 154 | (ASN1_STRING *) b->value.ptr); |
155 | break; | 155 | break; |
156 | } | 156 | } |
157 | 157 | ||
158 | return result; | 158 | return result; |
159 | } | 159 | } |
diff --git a/src/lib/libssl/src/crypto/asn1/a_utctm.c b/src/lib/libssl/src/crypto/asn1/a_utctm.c index 0e7aca90a7..e75f2ecbb6 100644 --- a/src/lib/libssl/src/crypto/asn1/a_utctm.c +++ b/src/lib/libssl/src/crypto/asn1/a_utctm.c | |||
@@ -64,41 +64,41 @@ | |||
64 | 64 | ||
65 | #if 0 | 65 | #if 0 |
66 | int i2d_ASN1_UTCTIME(ASN1_UTCTIME *a, unsigned char **pp) | 66 | int i2d_ASN1_UTCTIME(ASN1_UTCTIME *a, unsigned char **pp) |
67 | { | 67 | { |
68 | return(i2d_ASN1_bytes((ASN1_STRING *)a,pp, | 68 | return(i2d_ASN1_bytes((ASN1_STRING *)a,pp, |
69 | V_ASN1_UTCTIME,V_ASN1_UNIVERSAL)); | 69 | V_ASN1_UTCTIME,V_ASN1_UNIVERSAL)); |
70 | } | 70 | } |
71 | 71 | ||
72 | 72 | ||
73 | ASN1_UTCTIME *d2i_ASN1_UTCTIME(ASN1_UTCTIME **a, unsigned char **pp, | 73 | ASN1_UTCTIME *d2i_ASN1_UTCTIME(ASN1_UTCTIME **a, unsigned char **pp, |
74 | long length) | 74 | long length) |
75 | { | 75 | { |
76 | ASN1_UTCTIME *ret=NULL; | 76 | ASN1_UTCTIME *ret=NULL; |
77 | 77 | ||
78 | ret=(ASN1_UTCTIME *)d2i_ASN1_bytes((ASN1_STRING **)a,pp,length, | 78 | ret=(ASN1_UTCTIME *)d2i_ASN1_bytes((ASN1_STRING **)a,pp,length, |
79 | V_ASN1_UTCTIME,V_ASN1_UNIVERSAL); | 79 | V_ASN1_UTCTIME,V_ASN1_UNIVERSAL); |
80 | if (ret == NULL) | 80 | if (ret == NULL) |
81 | { | 81 | { |
82 | ASN1err(ASN1_F_D2I_ASN1_UTCTIME,ERR_R_NESTED_ASN1_ERROR); | 82 | ASN1err(ASN1_F_D2I_ASN1_UTCTIME,ERR_R_NESTED_ASN1_ERROR); |
83 | return(NULL); | 83 | return(NULL); |
84 | } | 84 | } |
85 | if (!ASN1_UTCTIME_check(ret)) | 85 | if (!ASN1_UTCTIME_check(ret)) |
86 | { | 86 | { |
87 | ASN1err(ASN1_F_D2I_ASN1_UTCTIME,ASN1_R_INVALID_TIME_FORMAT); | 87 | ASN1err(ASN1_F_D2I_ASN1_UTCTIME,ASN1_R_INVALID_TIME_FORMAT); |
88 | goto err; | 88 | goto err; |
89 | } | 89 | } |
90 | 90 | ||
91 | return(ret); | 91 | return(ret); |
92 | err: | 92 | err: |
93 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) | 93 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) |
94 | M_ASN1_UTCTIME_free(ret); | 94 | M_ASN1_UTCTIME_free(ret); |
95 | return(NULL); | 95 | return(NULL); |
96 | } | 96 | } |
97 | 97 | ||
98 | #endif | 98 | #endif |
99 | 99 | ||
100 | int ASN1_UTCTIME_check(ASN1_UTCTIME *d) | 100 | int ASN1_UTCTIME_check(ASN1_UTCTIME *d) |
101 | { | 101 | { |
102 | static const int min[8]={ 0, 1, 1, 0, 0, 0, 0, 0}; | 102 | static const int min[8]={ 0, 1, 1, 0, 0, 0, 0, 0}; |
103 | static const int max[8]={99,12,31,23,59,59,12,59}; | 103 | static const int max[8]={99,12,31,23,59,59,12,59}; |
104 | char *a; | 104 | char *a; |
@@ -111,10 +111,10 @@ int ASN1_UTCTIME_check(ASN1_UTCTIME *d) | |||
111 | 111 | ||
112 | if (l < 11) goto err; | 112 | if (l < 11) goto err; |
113 | for (i=0; i<6; i++) | 113 | for (i=0; i<6; i++) |
114 | { | 114 | { |
115 | if ((i == 5) && ((a[o] == 'Z') || | 115 | if ((i == 5) && ((a[o] == 'Z') || |
116 | (a[o] == '+') || (a[o] == '-'))) | 116 | (a[o] == '+') || (a[o] == '-'))) |
117 | { i++; break; } | 117 | { i++; break; } |
118 | if ((a[o] < '0') || (a[o] > '9')) goto err; | 118 | if ((a[o] < '0') || (a[o] > '9')) goto err; |
119 | n= a[o]-'0'; | 119 | n= a[o]-'0'; |
120 | if (++o > l) goto err; | 120 | if (++o > l) goto err; |
@@ -124,15 +124,15 @@ int ASN1_UTCTIME_check(ASN1_UTCTIME *d) | |||
124 | if (++o > l) goto err; | 124 | if (++o > l) goto err; |
125 | 125 | ||
126 | if ((n < min[i]) || (n > max[i])) goto err; | 126 | if ((n < min[i]) || (n > max[i])) goto err; |
127 | } | 127 | } |
128 | if (a[o] == 'Z') | 128 | if (a[o] == 'Z') |
129 | o++; | 129 | o++; |
130 | else if ((a[o] == '+') || (a[o] == '-')) | 130 | else if ((a[o] == '+') || (a[o] == '-')) |
131 | { | 131 | { |
132 | o++; | 132 | o++; |
133 | if (o+4 > l) goto err; | 133 | if (o+4 > l) goto err; |
134 | for (i=6; i<8; i++) | 134 | for (i=6; i<8; i++) |
135 | { | 135 | { |
136 | if ((a[o] < '0') || (a[o] > '9')) goto err; | 136 | if ((a[o] < '0') || (a[o] > '9')) goto err; |
137 | n= a[o]-'0'; | 137 | n= a[o]-'0'; |
138 | o++; | 138 | o++; |
@@ -140,43 +140,43 @@ int ASN1_UTCTIME_check(ASN1_UTCTIME *d) | |||
140 | n=(n*10)+ a[o]-'0'; | 140 | n=(n*10)+ a[o]-'0'; |
141 | if ((n < min[i]) || (n > max[i])) goto err; | 141 | if ((n < min[i]) || (n > max[i])) goto err; |
142 | o++; | 142 | o++; |
143 | } | ||
144 | } | 143 | } |
144 | } | ||
145 | return(o == l); | 145 | return(o == l); |
146 | err: | 146 | err: |
147 | return(0); | 147 | return(0); |
148 | } | 148 | } |
149 | 149 | ||
150 | int ASN1_UTCTIME_set_string(ASN1_UTCTIME *s, const char *str) | 150 | int ASN1_UTCTIME_set_string(ASN1_UTCTIME *s, const char *str) |
151 | { | 151 | { |
152 | ASN1_UTCTIME t; | 152 | ASN1_UTCTIME t; |
153 | 153 | ||
154 | t.type=V_ASN1_UTCTIME; | 154 | t.type=V_ASN1_UTCTIME; |
155 | t.length=strlen(str); | 155 | t.length=strlen(str); |
156 | t.data=(unsigned char *)str; | 156 | t.data=(unsigned char *)str; |
157 | if (ASN1_UTCTIME_check(&t)) | 157 | if (ASN1_UTCTIME_check(&t)) |
158 | { | 158 | { |
159 | if (s != NULL) | 159 | if (s != NULL) |
160 | { | 160 | { |
161 | if (!ASN1_STRING_set((ASN1_STRING *)s, | 161 | if (!ASN1_STRING_set((ASN1_STRING *)s, |
162 | (unsigned char *)str,t.length)) | 162 | (unsigned char *)str,t.length)) |
163 | return 0; | 163 | return 0; |
164 | s->type = V_ASN1_UTCTIME; | 164 | s->type = V_ASN1_UTCTIME; |
165 | } | ||
166 | return(1); | ||
167 | } | 165 | } |
166 | return(1); | ||
167 | } | ||
168 | else | 168 | else |
169 | return(0); | 169 | return(0); |
170 | } | 170 | } |
171 | 171 | ||
172 | ASN1_UTCTIME *ASN1_UTCTIME_set(ASN1_UTCTIME *s, time_t t) | 172 | ASN1_UTCTIME *ASN1_UTCTIME_set(ASN1_UTCTIME *s, time_t t) |
173 | { | 173 | { |
174 | return ASN1_UTCTIME_adj(s, t, 0, 0); | 174 | return ASN1_UTCTIME_adj(s, t, 0, 0); |
175 | } | 175 | } |
176 | 176 | ||
177 | ASN1_UTCTIME *ASN1_UTCTIME_adj(ASN1_UTCTIME *s, time_t t, | 177 | ASN1_UTCTIME *ASN1_UTCTIME_adj(ASN1_UTCTIME *s, time_t t, |
178 | int offset_day, long offset_sec) | 178 | int offset_day, long offset_sec) |
179 | { | 179 | { |
180 | char *p; | 180 | char *p; |
181 | struct tm *ts; | 181 | struct tm *ts; |
182 | struct tm data; | 182 | struct tm data; |
@@ -192,38 +192,38 @@ ASN1_UTCTIME *ASN1_UTCTIME_adj(ASN1_UTCTIME *s, time_t t, | |||
192 | return(NULL); | 192 | return(NULL); |
193 | 193 | ||
194 | if (offset_day || offset_sec) | 194 | if (offset_day || offset_sec) |
195 | { | 195 | { |
196 | if (!OPENSSL_gmtime_adj(ts, offset_day, offset_sec)) | 196 | if (!OPENSSL_gmtime_adj(ts, offset_day, offset_sec)) |
197 | return NULL; | 197 | return NULL; |
198 | } | 198 | } |
199 | 199 | ||
200 | if((ts->tm_year < 50) || (ts->tm_year >= 150)) | 200 | if((ts->tm_year < 50) || (ts->tm_year >= 150)) |
201 | return NULL; | 201 | return NULL; |
202 | 202 | ||
203 | p=(char *)s->data; | 203 | p=(char *)s->data; |
204 | if ((p == NULL) || ((size_t)s->length < len)) | 204 | if ((p == NULL) || ((size_t)s->length < len)) |
205 | { | 205 | { |
206 | p=malloc(len); | 206 | p=malloc(len); |
207 | if (p == NULL) | 207 | if (p == NULL) |
208 | { | 208 | { |
209 | ASN1err(ASN1_F_ASN1_UTCTIME_ADJ,ERR_R_MALLOC_FAILURE); | 209 | ASN1err(ASN1_F_ASN1_UTCTIME_ADJ,ERR_R_MALLOC_FAILURE); |
210 | return(NULL); | 210 | return(NULL); |
211 | } | 211 | } |
212 | if (s->data != NULL) | 212 | if (s->data != NULL) |
213 | free(s->data); | 213 | free(s->data); |
214 | s->data=(unsigned char *)p; | 214 | s->data=(unsigned char *)p; |
215 | } | 215 | } |
216 | 216 | ||
217 | (void) snprintf(p,len,"%02d%02d%02d%02d%02d%02dZ",ts->tm_year%100, | 217 | (void) snprintf(p,len,"%02d%02d%02d%02d%02d%02dZ",ts->tm_year%100, |
218 | ts->tm_mon+1,ts->tm_mday,ts->tm_hour,ts->tm_min,ts->tm_sec); | 218 | ts->tm_mon+1,ts->tm_mday,ts->tm_hour,ts->tm_min,ts->tm_sec); |
219 | s->length=strlen(p); | 219 | s->length=strlen(p); |
220 | s->type=V_ASN1_UTCTIME; | 220 | s->type=V_ASN1_UTCTIME; |
221 | return(s); | 221 | return(s); |
222 | } | 222 | } |
223 | 223 | ||
224 | 224 | ||
225 | int ASN1_UTCTIME_cmp_time_t(const ASN1_UTCTIME *s, time_t t) | 225 | int ASN1_UTCTIME_cmp_time_t(const ASN1_UTCTIME *s, time_t t) |
226 | { | 226 | { |
227 | struct tm *tm; | 227 | struct tm *tm; |
228 | struct tm data; | 228 | struct tm data; |
229 | int offset; | 229 | int offset; |
@@ -234,11 +234,11 @@ int ASN1_UTCTIME_cmp_time_t(const ASN1_UTCTIME *s, time_t t) | |||
234 | if (s->data[12] == 'Z') | 234 | if (s->data[12] == 'Z') |
235 | offset=0; | 235 | offset=0; |
236 | else | 236 | else |
237 | { | 237 | { |
238 | offset = g2(s->data+13)*60+g2(s->data+15); | 238 | offset = g2(s->data+13)*60+g2(s->data+15); |
239 | if (s->data[12] == '-') | 239 | if (s->data[12] == '-') |
240 | offset = -offset; | 240 | offset = -offset; |
241 | } | 241 | } |
242 | 242 | ||
243 | t -= offset*60; /* FIXME: may overflow in extreme cases */ | 243 | t -= offset*60; /* FIXME: may overflow in extreme cases */ |
244 | 244 | ||
@@ -258,12 +258,12 @@ int ASN1_UTCTIME_cmp_time_t(const ASN1_UTCTIME *s, time_t t) | |||
258 | #undef return_cmp | 258 | #undef return_cmp |
259 | 259 | ||
260 | return 0; | 260 | return 0; |
261 | } | 261 | } |
262 | 262 | ||
263 | 263 | ||
264 | #if 0 | 264 | #if 0 |
265 | time_t ASN1_UTCTIME_get(const ASN1_UTCTIME *s) | 265 | time_t ASN1_UTCTIME_get(const ASN1_UTCTIME *s) |
266 | { | 266 | { |
267 | struct tm tm; | 267 | struct tm tm; |
268 | int offset; | 268 | int offset; |
269 | 269 | ||
@@ -281,11 +281,11 @@ time_t ASN1_UTCTIME_get(const ASN1_UTCTIME *s) | |||
281 | if(s->data[12] == 'Z') | 281 | if(s->data[12] == 'Z') |
282 | offset=0; | 282 | offset=0; |
283 | else | 283 | else |
284 | { | 284 | { |
285 | offset=g2(s->data+13)*60+g2(s->data+15); | 285 | offset=g2(s->data+13)*60+g2(s->data+15); |
286 | if(s->data[12] == '-') | 286 | if(s->data[12] == '-') |
287 | offset= -offset; | 287 | offset= -offset; |
288 | } | 288 | } |
289 | #undef g2 | 289 | #undef g2 |
290 | 290 | ||
291 | return mktime(&tm)-offset*60; /* FIXME: mktime assumes the current timezone | 291 | return mktime(&tm)-offset*60; /* FIXME: mktime assumes the current timezone |
@@ -296,5 +296,5 @@ time_t ASN1_UTCTIME_get(const ASN1_UTCTIME *s) | |||
296 | * non-standard. | 296 | * non-standard. |
297 | * Also time_t is inappropriate for general | 297 | * Also time_t is inappropriate for general |
298 | * UTC times because it may a 32 bit type. */ | 298 | * UTC times because it may a 32 bit type. */ |
299 | } | 299 | } |
300 | #endif | 300 | #endif |
diff --git a/src/lib/libssl/src/crypto/asn1/a_verify.c b/src/lib/libssl/src/crypto/asn1/a_verify.c index 8eca970be3..59c5b876b5 100644 --- a/src/lib/libssl/src/crypto/asn1/a_verify.c +++ b/src/lib/libssl/src/crypto/asn1/a_verify.c | |||
@@ -74,7 +74,7 @@ | |||
74 | 74 | ||
75 | int ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a, | 75 | int ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a, |
76 | ASN1_BIT_STRING *signature, void *asn, EVP_PKEY *pkey) | 76 | ASN1_BIT_STRING *signature, void *asn, EVP_PKEY *pkey) |
77 | { | 77 | { |
78 | EVP_MD_CTX ctx; | 78 | EVP_MD_CTX ctx; |
79 | unsigned char *buf_in=NULL; | 79 | unsigned char *buf_in=NULL; |
80 | int ret= -1,inl; | 80 | int ret= -1,inl; |
@@ -82,26 +82,26 @@ int ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a, | |||
82 | int mdnid, pknid; | 82 | int mdnid, pknid; |
83 | 83 | ||
84 | if (!pkey) | 84 | if (!pkey) |
85 | { | 85 | { |
86 | ASN1err(ASN1_F_ASN1_ITEM_VERIFY, ERR_R_PASSED_NULL_PARAMETER); | 86 | ASN1err(ASN1_F_ASN1_ITEM_VERIFY, ERR_R_PASSED_NULL_PARAMETER); |
87 | return -1; | 87 | return -1; |
88 | } | 88 | } |
89 | 89 | ||
90 | EVP_MD_CTX_init(&ctx); | 90 | EVP_MD_CTX_init(&ctx); |
91 | 91 | ||
92 | /* Convert signature OID into digest and public key OIDs */ | 92 | /* Convert signature OID into digest and public key OIDs */ |
93 | if (!OBJ_find_sigid_algs(OBJ_obj2nid(a->algorithm), &mdnid, &pknid)) | 93 | if (!OBJ_find_sigid_algs(OBJ_obj2nid(a->algorithm), &mdnid, &pknid)) |
94 | { | 94 | { |
95 | ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ASN1_R_UNKNOWN_SIGNATURE_ALGORITHM); | 95 | ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ASN1_R_UNKNOWN_SIGNATURE_ALGORITHM); |
96 | goto err; | 96 | goto err; |
97 | } | 97 | } |
98 | if (mdnid == NID_undef) | 98 | if (mdnid == NID_undef) |
99 | { | 99 | { |
100 | if (!pkey->ameth || !pkey->ameth->item_verify) | 100 | if (!pkey->ameth || !pkey->ameth->item_verify) |
101 | { | 101 | { |
102 | ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ASN1_R_UNKNOWN_SIGNATURE_ALGORITHM); | 102 | ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ASN1_R_UNKNOWN_SIGNATURE_ALGORITHM); |
103 | goto err; | 103 | goto err; |
104 | } | 104 | } |
105 | ret = pkey->ameth->item_verify(&ctx, it, asn, a, | 105 | ret = pkey->ameth->item_verify(&ctx, it, asn, a, |
106 | signature, pkey); | 106 | signature, pkey); |
107 | /* Return value of 2 means carry on, anything else means we | 107 | /* Return value of 2 means carry on, anything else means we |
@@ -111,58 +111,58 @@ int ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a, | |||
111 | if (ret != 2) | 111 | if (ret != 2) |
112 | goto err; | 112 | goto err; |
113 | ret = -1; | 113 | ret = -1; |
114 | } | 114 | } |
115 | else | 115 | else |
116 | { | 116 | { |
117 | const EVP_MD *type; | 117 | const EVP_MD *type; |
118 | type=EVP_get_digestbynid(mdnid); | 118 | type=EVP_get_digestbynid(mdnid); |
119 | if (type == NULL) | 119 | if (type == NULL) |
120 | { | 120 | { |
121 | ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM); | 121 | ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM); |
122 | goto err; | 122 | goto err; |
123 | } | 123 | } |
124 | 124 | ||
125 | /* Check public key OID matches public key type */ | 125 | /* Check public key OID matches public key type */ |
126 | if (EVP_PKEY_type(pknid) != pkey->ameth->pkey_id) | 126 | if (EVP_PKEY_type(pknid) != pkey->ameth->pkey_id) |
127 | { | 127 | { |
128 | ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ASN1_R_WRONG_PUBLIC_KEY_TYPE); | 128 | ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ASN1_R_WRONG_PUBLIC_KEY_TYPE); |
129 | goto err; | 129 | goto err; |
130 | } | 130 | } |
131 | 131 | ||
132 | if (!EVP_DigestVerifyInit(&ctx, NULL, type, NULL, pkey)) | 132 | if (!EVP_DigestVerifyInit(&ctx, NULL, type, NULL, pkey)) |
133 | { | 133 | { |
134 | ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ERR_R_EVP_LIB); | 134 | ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ERR_R_EVP_LIB); |
135 | ret=0; | 135 | ret=0; |
136 | goto err; | 136 | goto err; |
137 | } | ||
138 | |||
139 | } | 137 | } |
140 | 138 | ||
139 | } | ||
140 | |||
141 | inl = ASN1_item_i2d(asn, &buf_in, it); | 141 | inl = ASN1_item_i2d(asn, &buf_in, it); |
142 | 142 | ||
143 | if (buf_in == NULL) | 143 | if (buf_in == NULL) |
144 | { | 144 | { |
145 | ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ERR_R_MALLOC_FAILURE); | 145 | ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ERR_R_MALLOC_FAILURE); |
146 | goto err; | 146 | goto err; |
147 | } | 147 | } |
148 | 148 | ||
149 | if (!EVP_DigestVerifyUpdate(&ctx,buf_in,inl)) | 149 | if (!EVP_DigestVerifyUpdate(&ctx,buf_in,inl)) |
150 | { | 150 | { |
151 | ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ERR_R_EVP_LIB); | 151 | ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ERR_R_EVP_LIB); |
152 | ret=0; | 152 | ret=0; |
153 | goto err; | 153 | goto err; |
154 | } | 154 | } |
155 | 155 | ||
156 | OPENSSL_cleanse(buf_in,(unsigned int)inl); | 156 | OPENSSL_cleanse(buf_in,(unsigned int)inl); |
157 | free(buf_in); | 157 | free(buf_in); |
158 | 158 | ||
159 | if (EVP_DigestVerifyFinal(&ctx,signature->data, | 159 | if (EVP_DigestVerifyFinal(&ctx,signature->data, |
160 | (size_t)signature->length) <= 0) | 160 | (size_t)signature->length) <= 0) |
161 | { | 161 | { |
162 | ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ERR_R_EVP_LIB); | 162 | ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ERR_R_EVP_LIB); |
163 | ret=0; | 163 | ret=0; |
164 | goto err; | 164 | goto err; |
165 | } | 165 | } |
166 | /* we don't need to zero the 'ctx' because we just checked | 166 | /* we don't need to zero the 'ctx' because we just checked |
167 | * public information */ | 167 | * public information */ |
168 | /* memset(&ctx,0,sizeof(ctx)); */ | 168 | /* memset(&ctx,0,sizeof(ctx)); */ |
@@ -170,6 +170,6 @@ int ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a, | |||
170 | err: | 170 | err: |
171 | EVP_MD_CTX_cleanup(&ctx); | 171 | EVP_MD_CTX_cleanup(&ctx); |
172 | return(ret); | 172 | return(ret); |
173 | } | 173 | } |
174 | 174 | ||
175 | 175 | ||
diff --git a/src/lib/libssl/src/crypto/asn1/ameth_lib.c b/src/lib/libssl/src/crypto/asn1/ameth_lib.c index 228392f1e6..8f96e00c93 100644 --- a/src/lib/libssl/src/crypto/asn1/ameth_lib.c +++ b/src/lib/libssl/src/crypto/asn1/ameth_lib.c | |||
@@ -73,7 +73,7 @@ extern const EVP_PKEY_ASN1_METHOD cmac_asn1_meth; | |||
73 | 73 | ||
74 | /* Keep this sorted in type order !! */ | 74 | /* Keep this sorted in type order !! */ |
75 | static const EVP_PKEY_ASN1_METHOD *standard_methods[] = | 75 | static const EVP_PKEY_ASN1_METHOD *standard_methods[] = |
76 | { | 76 | { |
77 | #ifndef OPENSSL_NO_RSA | 77 | #ifndef OPENSSL_NO_RSA |
78 | &rsa_asn1_meths[0], | 78 | &rsa_asn1_meths[0], |
79 | &rsa_asn1_meths[1], | 79 | &rsa_asn1_meths[1], |
@@ -93,7 +93,7 @@ static const EVP_PKEY_ASN1_METHOD *standard_methods[] = | |||
93 | #endif | 93 | #endif |
94 | &hmac_asn1_meth, | 94 | &hmac_asn1_meth, |
95 | &cmac_asn1_meth | 95 | &cmac_asn1_meth |
96 | }; | 96 | }; |
97 | 97 | ||
98 | typedef int sk_cmp_fn_type(const char * const *a, const char * const *b); | 98 | typedef int sk_cmp_fn_type(const char * const *a, const char * const *b); |
99 | DECLARE_STACK_OF(EVP_PKEY_ASN1_METHOD) | 99 | DECLARE_STACK_OF(EVP_PKEY_ASN1_METHOD) |
@@ -103,7 +103,7 @@ static STACK_OF(EVP_PKEY_ASN1_METHOD) *app_methods = NULL; | |||
103 | 103 | ||
104 | #ifdef TEST | 104 | #ifdef TEST |
105 | void main() | 105 | void main() |
106 | { | 106 | { |
107 | int i; | 107 | int i; |
108 | for (i = 0; | 108 | for (i = 0; |
109 | i < sizeof(standard_methods)/sizeof(EVP_PKEY_ASN1_METHOD *); | 109 | i < sizeof(standard_methods)/sizeof(EVP_PKEY_ASN1_METHOD *); |
@@ -111,7 +111,7 @@ void main() | |||
111 | fprintf(stderr, "Number %d id=%d (%s)\n", i, | 111 | fprintf(stderr, "Number %d id=%d (%s)\n", i, |
112 | standard_methods[i]->pkey_id, | 112 | standard_methods[i]->pkey_id, |
113 | OBJ_nid2sn(standard_methods[i]->pkey_id)); | 113 | OBJ_nid2sn(standard_methods[i]->pkey_id)); |
114 | } | 114 | } |
115 | #endif | 115 | #endif |
116 | 116 | ||
117 | DECLARE_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_ASN1_METHOD *, | 117 | DECLARE_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_ASN1_METHOD *, |
@@ -119,23 +119,23 @@ DECLARE_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_ASN1_METHOD *, | |||
119 | 119 | ||
120 | static int ameth_cmp(const EVP_PKEY_ASN1_METHOD * const *a, | 120 | static int ameth_cmp(const EVP_PKEY_ASN1_METHOD * const *a, |
121 | const EVP_PKEY_ASN1_METHOD * const *b) | 121 | const EVP_PKEY_ASN1_METHOD * const *b) |
122 | { | 122 | { |
123 | return ((*a)->pkey_id - (*b)->pkey_id); | 123 | return ((*a)->pkey_id - (*b)->pkey_id); |
124 | } | 124 | } |
125 | 125 | ||
126 | IMPLEMENT_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_ASN1_METHOD *, | 126 | IMPLEMENT_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_ASN1_METHOD *, |
127 | const EVP_PKEY_ASN1_METHOD *, ameth); | 127 | const EVP_PKEY_ASN1_METHOD *, ameth); |
128 | 128 | ||
129 | int EVP_PKEY_asn1_get_count(void) | 129 | int EVP_PKEY_asn1_get_count(void) |
130 | { | 130 | { |
131 | int num = sizeof(standard_methods)/sizeof(EVP_PKEY_ASN1_METHOD *); | 131 | int num = sizeof(standard_methods)/sizeof(EVP_PKEY_ASN1_METHOD *); |
132 | if (app_methods) | 132 | if (app_methods) |
133 | num += sk_EVP_PKEY_ASN1_METHOD_num(app_methods); | 133 | num += sk_EVP_PKEY_ASN1_METHOD_num(app_methods); |
134 | return num; | 134 | return num; |
135 | } | 135 | } |
136 | 136 | ||
137 | const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_get0(int idx) | 137 | const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_get0(int idx) |
138 | { | 138 | { |
139 | int num = sizeof(standard_methods)/sizeof(EVP_PKEY_ASN1_METHOD *); | 139 | int num = sizeof(standard_methods)/sizeof(EVP_PKEY_ASN1_METHOD *); |
140 | if (idx < 0) | 140 | if (idx < 0) |
141 | return NULL; | 141 | return NULL; |
@@ -143,27 +143,27 @@ const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_get0(int idx) | |||
143 | return standard_methods[idx]; | 143 | return standard_methods[idx]; |
144 | idx -= num; | 144 | idx -= num; |
145 | return sk_EVP_PKEY_ASN1_METHOD_value(app_methods, idx); | 145 | return sk_EVP_PKEY_ASN1_METHOD_value(app_methods, idx); |
146 | } | 146 | } |
147 | 147 | ||
148 | static const EVP_PKEY_ASN1_METHOD *pkey_asn1_find(int type) | 148 | static const EVP_PKEY_ASN1_METHOD *pkey_asn1_find(int type) |
149 | { | 149 | { |
150 | EVP_PKEY_ASN1_METHOD tmp; | 150 | EVP_PKEY_ASN1_METHOD tmp; |
151 | const EVP_PKEY_ASN1_METHOD *t = &tmp, **ret; | 151 | const EVP_PKEY_ASN1_METHOD *t = &tmp, **ret; |
152 | tmp.pkey_id = type; | 152 | tmp.pkey_id = type; |
153 | if (app_methods) | 153 | if (app_methods) |
154 | { | 154 | { |
155 | int idx; | 155 | int idx; |
156 | idx = sk_EVP_PKEY_ASN1_METHOD_find(app_methods, &tmp); | 156 | idx = sk_EVP_PKEY_ASN1_METHOD_find(app_methods, &tmp); |
157 | if (idx >= 0) | 157 | if (idx >= 0) |
158 | return sk_EVP_PKEY_ASN1_METHOD_value(app_methods, idx); | 158 | return sk_EVP_PKEY_ASN1_METHOD_value(app_methods, idx); |
159 | } | 159 | } |
160 | ret = OBJ_bsearch_ameth(&t, standard_methods, | 160 | ret = OBJ_bsearch_ameth(&t, standard_methods, |
161 | sizeof(standard_methods) | 161 | sizeof(standard_methods) |
162 | /sizeof(EVP_PKEY_ASN1_METHOD *)); | 162 | /sizeof(EVP_PKEY_ASN1_METHOD *)); |
163 | if (!ret || !*ret) | 163 | if (!ret || !*ret) |
164 | return NULL; | 164 | return NULL; |
165 | return *ret; | 165 | return *ret; |
166 | } | 166 | } |
167 | 167 | ||
168 | /* Find an implementation of an ASN1 algorithm. If 'pe' is not NULL | 168 | /* Find an implementation of an ASN1 algorithm. If 'pe' is not NULL |
169 | * also search through engines and set *pe to a functional reference | 169 | * also search through engines and set *pe to a functional reference |
@@ -172,47 +172,47 @@ static const EVP_PKEY_ASN1_METHOD *pkey_asn1_find(int type) | |||
172 | */ | 172 | */ |
173 | 173 | ||
174 | const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_find(ENGINE **pe, int type) | 174 | const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_find(ENGINE **pe, int type) |
175 | { | 175 | { |
176 | const EVP_PKEY_ASN1_METHOD *t; | 176 | const EVP_PKEY_ASN1_METHOD *t; |
177 | 177 | ||
178 | for (;;) | 178 | for (;;) |
179 | { | 179 | { |
180 | t = pkey_asn1_find(type); | 180 | t = pkey_asn1_find(type); |
181 | if (!t || !(t->pkey_flags & ASN1_PKEY_ALIAS)) | 181 | if (!t || !(t->pkey_flags & ASN1_PKEY_ALIAS)) |
182 | break; | 182 | break; |
183 | type = t->pkey_base_id; | 183 | type = t->pkey_base_id; |
184 | } | 184 | } |
185 | if (pe) | 185 | if (pe) |
186 | { | 186 | { |
187 | #ifndef OPENSSL_NO_ENGINE | 187 | #ifndef OPENSSL_NO_ENGINE |
188 | ENGINE *e; | 188 | ENGINE *e; |
189 | /* type will contain the final unaliased type */ | 189 | /* type will contain the final unaliased type */ |
190 | e = ENGINE_get_pkey_asn1_meth_engine(type); | 190 | e = ENGINE_get_pkey_asn1_meth_engine(type); |
191 | if (e) | 191 | if (e) |
192 | { | 192 | { |
193 | *pe = e; | 193 | *pe = e; |
194 | return ENGINE_get_pkey_asn1_meth(e, type); | 194 | return ENGINE_get_pkey_asn1_meth(e, type); |
195 | } | 195 | } |
196 | #endif | 196 | #endif |
197 | *pe = NULL; | 197 | *pe = NULL; |
198 | } | ||
199 | return t; | ||
200 | } | 198 | } |
199 | return t; | ||
200 | } | ||
201 | 201 | ||
202 | const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_find_str(ENGINE **pe, | 202 | const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_find_str(ENGINE **pe, |
203 | const char *str, int len) | 203 | const char *str, int len) |
204 | { | 204 | { |
205 | int i; | 205 | int i; |
206 | const EVP_PKEY_ASN1_METHOD *ameth; | 206 | const EVP_PKEY_ASN1_METHOD *ameth; |
207 | if (len == -1) | 207 | if (len == -1) |
208 | len = strlen(str); | 208 | len = strlen(str); |
209 | if (pe) | 209 | if (pe) |
210 | { | 210 | { |
211 | #ifndef OPENSSL_NO_ENGINE | 211 | #ifndef OPENSSL_NO_ENGINE |
212 | ENGINE *e; | 212 | ENGINE *e; |
213 | ameth = ENGINE_pkey_asn1_find_str(&e, str, len); | 213 | ameth = ENGINE_pkey_asn1_find_str(&e, str, len); |
214 | if (ameth) | 214 | if (ameth) |
215 | { | 215 | { |
216 | /* Convert structural into | 216 | /* Convert structural into |
217 | * functional reference | 217 | * functional reference |
218 | */ | 218 | */ |
@@ -221,50 +221,50 @@ const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_find_str(ENGINE **pe, | |||
221 | ENGINE_free(e); | 221 | ENGINE_free(e); |
222 | *pe = e; | 222 | *pe = e; |
223 | return ameth; | 223 | return ameth; |
224 | } | 224 | } |
225 | #endif | 225 | #endif |
226 | *pe = NULL; | 226 | *pe = NULL; |
227 | } | 227 | } |
228 | for (i = 0; i < EVP_PKEY_asn1_get_count(); i++) | 228 | for (i = 0; i < EVP_PKEY_asn1_get_count(); i++) |
229 | { | 229 | { |
230 | ameth = EVP_PKEY_asn1_get0(i); | 230 | ameth = EVP_PKEY_asn1_get0(i); |
231 | if (ameth->pkey_flags & ASN1_PKEY_ALIAS) | 231 | if (ameth->pkey_flags & ASN1_PKEY_ALIAS) |
232 | continue; | 232 | continue; |
233 | if (((int)strlen(ameth->pem_str) == len) && | 233 | if (((int)strlen(ameth->pem_str) == len) && |
234 | !strncasecmp(ameth->pem_str, str, len)) | 234 | !strncasecmp(ameth->pem_str, str, len)) |
235 | return ameth; | 235 | return ameth; |
236 | } | ||
237 | return NULL; | ||
238 | } | 236 | } |
237 | return NULL; | ||
238 | } | ||
239 | 239 | ||
240 | int EVP_PKEY_asn1_add0(const EVP_PKEY_ASN1_METHOD *ameth) | 240 | int EVP_PKEY_asn1_add0(const EVP_PKEY_ASN1_METHOD *ameth) |
241 | { | 241 | { |
242 | if (app_methods == NULL) | 242 | if (app_methods == NULL) |
243 | { | 243 | { |
244 | app_methods = sk_EVP_PKEY_ASN1_METHOD_new(ameth_cmp); | 244 | app_methods = sk_EVP_PKEY_ASN1_METHOD_new(ameth_cmp); |
245 | if (!app_methods) | 245 | if (!app_methods) |
246 | return 0; | 246 | return 0; |
247 | } | 247 | } |
248 | if (!sk_EVP_PKEY_ASN1_METHOD_push(app_methods, ameth)) | 248 | if (!sk_EVP_PKEY_ASN1_METHOD_push(app_methods, ameth)) |
249 | return 0; | 249 | return 0; |
250 | sk_EVP_PKEY_ASN1_METHOD_sort(app_methods); | 250 | sk_EVP_PKEY_ASN1_METHOD_sort(app_methods); |
251 | return 1; | 251 | return 1; |
252 | } | 252 | } |
253 | 253 | ||
254 | int EVP_PKEY_asn1_add_alias(int to, int from) | 254 | int EVP_PKEY_asn1_add_alias(int to, int from) |
255 | { | 255 | { |
256 | EVP_PKEY_ASN1_METHOD *ameth; | 256 | EVP_PKEY_ASN1_METHOD *ameth; |
257 | ameth = EVP_PKEY_asn1_new(from, ASN1_PKEY_ALIAS, NULL, NULL); | 257 | ameth = EVP_PKEY_asn1_new(from, ASN1_PKEY_ALIAS, NULL, NULL); |
258 | if (!ameth) | 258 | if (!ameth) |
259 | return 0; | 259 | return 0; |
260 | ameth->pkey_base_id = to; | 260 | ameth->pkey_base_id = to; |
261 | return EVP_PKEY_asn1_add0(ameth); | 261 | return EVP_PKEY_asn1_add0(ameth); |
262 | } | 262 | } |
263 | 263 | ||
264 | int EVP_PKEY_asn1_get0_info(int *ppkey_id, int *ppkey_base_id, int *ppkey_flags, | 264 | int EVP_PKEY_asn1_get0_info(int *ppkey_id, int *ppkey_base_id, int *ppkey_flags, |
265 | const char **pinfo, const char **ppem_str, | 265 | const char **pinfo, const char **ppem_str, |
266 | const EVP_PKEY_ASN1_METHOD *ameth) | 266 | const EVP_PKEY_ASN1_METHOD *ameth) |
267 | { | 267 | { |
268 | if (!ameth) | 268 | if (!ameth) |
269 | return 0; | 269 | return 0; |
270 | if (ppkey_id) | 270 | if (ppkey_id) |
@@ -278,16 +278,16 @@ int EVP_PKEY_asn1_get0_info(int *ppkey_id, int *ppkey_base_id, int *ppkey_flags, | |||
278 | if (ppem_str) | 278 | if (ppem_str) |
279 | *ppem_str = ameth->pem_str; | 279 | *ppem_str = ameth->pem_str; |
280 | return 1; | 280 | return 1; |
281 | } | 281 | } |
282 | 282 | ||
283 | const EVP_PKEY_ASN1_METHOD* EVP_PKEY_get0_asn1(EVP_PKEY *pkey) | 283 | const EVP_PKEY_ASN1_METHOD* EVP_PKEY_get0_asn1(EVP_PKEY *pkey) |
284 | { | 284 | { |
285 | return pkey->ameth; | 285 | return pkey->ameth; |
286 | } | 286 | } |
287 | 287 | ||
288 | EVP_PKEY_ASN1_METHOD* EVP_PKEY_asn1_new(int id, int flags, | 288 | EVP_PKEY_ASN1_METHOD* EVP_PKEY_asn1_new(int id, int flags, |
289 | const char *pem_str, const char *info) | 289 | const char *pem_str, const char *info) |
290 | { | 290 | { |
291 | EVP_PKEY_ASN1_METHOD *ameth; | 291 | EVP_PKEY_ASN1_METHOD *ameth; |
292 | ameth = malloc(sizeof(EVP_PKEY_ASN1_METHOD)); | 292 | ameth = malloc(sizeof(EVP_PKEY_ASN1_METHOD)); |
293 | if (!ameth) | 293 | if (!ameth) |
@@ -300,20 +300,20 @@ EVP_PKEY_ASN1_METHOD* EVP_PKEY_asn1_new(int id, int flags, | |||
300 | ameth->pkey_flags = flags | ASN1_PKEY_DYNAMIC; | 300 | ameth->pkey_flags = flags | ASN1_PKEY_DYNAMIC; |
301 | 301 | ||
302 | if (info) | 302 | if (info) |
303 | { | 303 | { |
304 | ameth->info = BUF_strdup(info); | 304 | ameth->info = BUF_strdup(info); |
305 | if (!ameth->info) | 305 | if (!ameth->info) |
306 | goto err; | 306 | goto err; |
307 | } | 307 | } |
308 | else | 308 | else |
309 | ameth->info = NULL; | 309 | ameth->info = NULL; |
310 | 310 | ||
311 | if (pem_str) | 311 | if (pem_str) |
312 | { | 312 | { |
313 | ameth->pem_str = BUF_strdup(pem_str); | 313 | ameth->pem_str = BUF_strdup(pem_str); |
314 | if (!ameth->pem_str) | 314 | if (!ameth->pem_str) |
315 | goto err; | 315 | goto err; |
316 | } | 316 | } |
317 | else | 317 | else |
318 | ameth->pem_str = NULL; | 318 | ameth->pem_str = NULL; |
319 | 319 | ||
@@ -352,11 +352,11 @@ EVP_PKEY_ASN1_METHOD* EVP_PKEY_asn1_new(int id, int flags, | |||
352 | EVP_PKEY_asn1_free(ameth); | 352 | EVP_PKEY_asn1_free(ameth); |
353 | return NULL; | 353 | return NULL; |
354 | 354 | ||
355 | } | 355 | } |
356 | 356 | ||
357 | void EVP_PKEY_asn1_copy(EVP_PKEY_ASN1_METHOD *dst, | 357 | void EVP_PKEY_asn1_copy(EVP_PKEY_ASN1_METHOD *dst, |
358 | const EVP_PKEY_ASN1_METHOD *src) | 358 | const EVP_PKEY_ASN1_METHOD *src) |
359 | { | 359 | { |
360 | 360 | ||
361 | dst->pub_decode = src->pub_decode; | 361 | dst->pub_decode = src->pub_decode; |
362 | dst->pub_encode = src->pub_encode; | 362 | dst->pub_encode = src->pub_encode; |
@@ -386,19 +386,19 @@ void EVP_PKEY_asn1_copy(EVP_PKEY_ASN1_METHOD *dst, | |||
386 | dst->item_sign = src->item_sign; | 386 | dst->item_sign = src->item_sign; |
387 | dst->item_verify = src->item_verify; | 387 | dst->item_verify = src->item_verify; |
388 | 388 | ||
389 | } | 389 | } |
390 | 390 | ||
391 | void EVP_PKEY_asn1_free(EVP_PKEY_ASN1_METHOD *ameth) | 391 | void EVP_PKEY_asn1_free(EVP_PKEY_ASN1_METHOD *ameth) |
392 | { | 392 | { |
393 | if (ameth && (ameth->pkey_flags & ASN1_PKEY_DYNAMIC)) | 393 | if (ameth && (ameth->pkey_flags & ASN1_PKEY_DYNAMIC)) |
394 | { | 394 | { |
395 | if (ameth->pem_str) | 395 | if (ameth->pem_str) |
396 | free(ameth->pem_str); | 396 | free(ameth->pem_str); |
397 | if (ameth->info) | 397 | if (ameth->info) |
398 | free(ameth->info); | 398 | free(ameth->info); |
399 | free(ameth); | 399 | free(ameth); |
400 | } | ||
401 | } | 400 | } |
401 | } | ||
402 | 402 | ||
403 | void EVP_PKEY_asn1_set_public(EVP_PKEY_ASN1_METHOD *ameth, | 403 | void EVP_PKEY_asn1_set_public(EVP_PKEY_ASN1_METHOD *ameth, |
404 | int (*pub_decode)(EVP_PKEY *pk, X509_PUBKEY *pub), | 404 | int (*pub_decode)(EVP_PKEY *pk, X509_PUBKEY *pub), |
@@ -408,25 +408,25 @@ void EVP_PKEY_asn1_set_public(EVP_PKEY_ASN1_METHOD *ameth, | |||
408 | ASN1_PCTX *pctx), | 408 | ASN1_PCTX *pctx), |
409 | int (*pkey_size)(const EVP_PKEY *pk), | 409 | int (*pkey_size)(const EVP_PKEY *pk), |
410 | int (*pkey_bits)(const EVP_PKEY *pk)) | 410 | int (*pkey_bits)(const EVP_PKEY *pk)) |
411 | { | 411 | { |
412 | ameth->pub_decode = pub_decode; | 412 | ameth->pub_decode = pub_decode; |
413 | ameth->pub_encode = pub_encode; | 413 | ameth->pub_encode = pub_encode; |
414 | ameth->pub_cmp = pub_cmp; | 414 | ameth->pub_cmp = pub_cmp; |
415 | ameth->pub_print = pub_print; | 415 | ameth->pub_print = pub_print; |
416 | ameth->pkey_size = pkey_size; | 416 | ameth->pkey_size = pkey_size; |
417 | ameth->pkey_bits = pkey_bits; | 417 | ameth->pkey_bits = pkey_bits; |
418 | } | 418 | } |
419 | 419 | ||
420 | void EVP_PKEY_asn1_set_private(EVP_PKEY_ASN1_METHOD *ameth, | 420 | void EVP_PKEY_asn1_set_private(EVP_PKEY_ASN1_METHOD *ameth, |
421 | int (*priv_decode)(EVP_PKEY *pk, PKCS8_PRIV_KEY_INFO *p8inf), | 421 | int (*priv_decode)(EVP_PKEY *pk, PKCS8_PRIV_KEY_INFO *p8inf), |
422 | int (*priv_encode)(PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pk), | 422 | int (*priv_encode)(PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pk), |
423 | int (*priv_print)(BIO *out, const EVP_PKEY *pkey, int indent, | 423 | int (*priv_print)(BIO *out, const EVP_PKEY *pkey, int indent, |
424 | ASN1_PCTX *pctx)) | 424 | ASN1_PCTX *pctx)) |
425 | { | 425 | { |
426 | ameth->priv_decode = priv_decode; | 426 | ameth->priv_decode = priv_decode; |
427 | ameth->priv_encode = priv_encode; | 427 | ameth->priv_encode = priv_encode; |
428 | ameth->priv_print = priv_print; | 428 | ameth->priv_print = priv_print; |
429 | } | 429 | } |
430 | 430 | ||
431 | void EVP_PKEY_asn1_set_param(EVP_PKEY_ASN1_METHOD *ameth, | 431 | void EVP_PKEY_asn1_set_param(EVP_PKEY_ASN1_METHOD *ameth, |
432 | int (*param_decode)(EVP_PKEY *pkey, | 432 | int (*param_decode)(EVP_PKEY *pkey, |
@@ -437,24 +437,24 @@ void EVP_PKEY_asn1_set_param(EVP_PKEY_ASN1_METHOD *ameth, | |||
437 | int (*param_cmp)(const EVP_PKEY *a, const EVP_PKEY *b), | 437 | int (*param_cmp)(const EVP_PKEY *a, const EVP_PKEY *b), |
438 | int (*param_print)(BIO *out, const EVP_PKEY *pkey, int indent, | 438 | int (*param_print)(BIO *out, const EVP_PKEY *pkey, int indent, |
439 | ASN1_PCTX *pctx)) | 439 | ASN1_PCTX *pctx)) |
440 | { | 440 | { |
441 | ameth->param_decode = param_decode; | 441 | ameth->param_decode = param_decode; |
442 | ameth->param_encode = param_encode; | 442 | ameth->param_encode = param_encode; |
443 | ameth->param_missing = param_missing; | 443 | ameth->param_missing = param_missing; |
444 | ameth->param_copy = param_copy; | 444 | ameth->param_copy = param_copy; |
445 | ameth->param_cmp = param_cmp; | 445 | ameth->param_cmp = param_cmp; |
446 | ameth->param_print = param_print; | 446 | ameth->param_print = param_print; |
447 | } | 447 | } |
448 | 448 | ||
449 | void EVP_PKEY_asn1_set_free(EVP_PKEY_ASN1_METHOD *ameth, | 449 | void EVP_PKEY_asn1_set_free(EVP_PKEY_ASN1_METHOD *ameth, |
450 | void (*pkey_free)(EVP_PKEY *pkey)) | 450 | void (*pkey_free)(EVP_PKEY *pkey)) |
451 | { | 451 | { |
452 | ameth->pkey_free = pkey_free; | 452 | ameth->pkey_free = pkey_free; |
453 | } | 453 | } |
454 | 454 | ||
455 | void EVP_PKEY_asn1_set_ctrl(EVP_PKEY_ASN1_METHOD *ameth, | 455 | void EVP_PKEY_asn1_set_ctrl(EVP_PKEY_ASN1_METHOD *ameth, |
456 | int (*pkey_ctrl)(EVP_PKEY *pkey, int op, | 456 | int (*pkey_ctrl)(EVP_PKEY *pkey, int op, |
457 | long arg1, void *arg2)) | 457 | long arg1, void *arg2)) |
458 | { | 458 | { |
459 | ameth->pkey_ctrl = pkey_ctrl; | 459 | ameth->pkey_ctrl = pkey_ctrl; |
460 | } | 460 | } |
diff --git a/src/lib/libssl/src/crypto/asn1/asn1_err.c b/src/lib/libssl/src/crypto/asn1/asn1_err.c index aa60203ba8..582f613744 100644 --- a/src/lib/libssl/src/crypto/asn1/asn1_err.c +++ b/src/lib/libssl/src/crypto/asn1/asn1_err.c | |||
@@ -69,7 +69,7 @@ | |||
69 | #define ERR_REASON(reason) ERR_PACK(ERR_LIB_ASN1,0,reason) | 69 | #define ERR_REASON(reason) ERR_PACK(ERR_LIB_ASN1,0,reason) |
70 | 70 | ||
71 | static ERR_STRING_DATA ASN1_str_functs[]= | 71 | static ERR_STRING_DATA ASN1_str_functs[]= |
72 | { | 72 | { |
73 | {ERR_FUNC(ASN1_F_A2D_ASN1_OBJECT), "a2d_ASN1_OBJECT"}, | 73 | {ERR_FUNC(ASN1_F_A2D_ASN1_OBJECT), "a2d_ASN1_OBJECT"}, |
74 | {ERR_FUNC(ASN1_F_A2I_ASN1_ENUMERATED), "a2i_ASN1_ENUMERATED"}, | 74 | {ERR_FUNC(ASN1_F_A2I_ASN1_ENUMERATED), "a2i_ASN1_ENUMERATED"}, |
75 | {ERR_FUNC(ASN1_F_A2I_ASN1_INTEGER), "a2i_ASN1_INTEGER"}, | 75 | {ERR_FUNC(ASN1_F_A2I_ASN1_INTEGER), "a2i_ASN1_INTEGER"}, |
@@ -192,10 +192,10 @@ static ERR_STRING_DATA ASN1_str_functs[]= | |||
192 | {ERR_FUNC(ASN1_F_X509_NEW), "X509_NEW"}, | 192 | {ERR_FUNC(ASN1_F_X509_NEW), "X509_NEW"}, |
193 | {ERR_FUNC(ASN1_F_X509_PKEY_NEW), "X509_PKEY_new"}, | 193 | {ERR_FUNC(ASN1_F_X509_PKEY_NEW), "X509_PKEY_new"}, |
194 | {0,NULL} | 194 | {0,NULL} |
195 | }; | 195 | }; |
196 | 196 | ||
197 | static ERR_STRING_DATA ASN1_str_reasons[]= | 197 | static ERR_STRING_DATA ASN1_str_reasons[]= |
198 | { | 198 | { |
199 | {ERR_REASON(ASN1_R_ADDING_OBJECT) ,"adding object"}, | 199 | {ERR_REASON(ASN1_R_ADDING_OBJECT) ,"adding object"}, |
200 | {ERR_REASON(ASN1_R_ASN1_PARSE_ERROR) ,"asn1 parse error"}, | 200 | {ERR_REASON(ASN1_R_ASN1_PARSE_ERROR) ,"asn1 parse error"}, |
201 | {ERR_REASON(ASN1_R_ASN1_SIG_PARSE_ERROR) ,"asn1 sig parse error"}, | 201 | {ERR_REASON(ASN1_R_ASN1_SIG_PARSE_ERROR) ,"asn1 sig parse error"}, |
@@ -315,18 +315,18 @@ static ERR_STRING_DATA ASN1_str_reasons[]= | |||
315 | {ERR_REASON(ASN1_R_WRONG_TAG) ,"wrong tag"}, | 315 | {ERR_REASON(ASN1_R_WRONG_TAG) ,"wrong tag"}, |
316 | {ERR_REASON(ASN1_R_WRONG_TYPE) ,"wrong type"}, | 316 | {ERR_REASON(ASN1_R_WRONG_TYPE) ,"wrong type"}, |
317 | {0,NULL} | 317 | {0,NULL} |
318 | }; | 318 | }; |
319 | 319 | ||
320 | #endif | 320 | #endif |
321 | 321 | ||
322 | void ERR_load_ASN1_strings(void) | 322 | void ERR_load_ASN1_strings(void) |
323 | { | 323 | { |
324 | #ifndef OPENSSL_NO_ERR | 324 | #ifndef OPENSSL_NO_ERR |
325 | 325 | ||
326 | if (ERR_func_error_string(ASN1_str_functs[0].error) == NULL) | 326 | if (ERR_func_error_string(ASN1_str_functs[0].error) == NULL) |
327 | { | 327 | { |
328 | ERR_load_strings(0,ASN1_str_functs); | 328 | ERR_load_strings(0,ASN1_str_functs); |
329 | ERR_load_strings(0,ASN1_str_reasons); | 329 | ERR_load_strings(0,ASN1_str_reasons); |
330 | } | ||
331 | #endif | ||
332 | } | 330 | } |
331 | #endif | ||
332 | } | ||
diff --git a/src/lib/libssl/src/crypto/asn1/asn1_gen.c b/src/lib/libssl/src/crypto/asn1/asn1_gen.c index 8194beeb30..f78aac7148 100644 --- a/src/lib/libssl/src/crypto/asn1/asn1_gen.c +++ b/src/lib/libssl/src/crypto/asn1/asn1_gen.c | |||
@@ -70,7 +70,7 @@ | |||
70 | #define ASN1_GEN_FLAG_SETWRAP (ASN1_GEN_FLAG|7) | 70 | #define ASN1_GEN_FLAG_SETWRAP (ASN1_GEN_FLAG|7) |
71 | #define ASN1_GEN_FLAG_FORMAT (ASN1_GEN_FLAG|8) | 71 | #define ASN1_GEN_FLAG_FORMAT (ASN1_GEN_FLAG|8) |
72 | 72 | ||
73 | #define ASN1_GEN_STR(str,val) {str, sizeof(str) - 1, val} | 73 | #define ASN1_GEN_STR(str,val){str, sizeof(str) - 1, val} |
74 | 74 | ||
75 | #define ASN1_FLAG_EXP_MAX 20 | 75 | #define ASN1_FLAG_EXP_MAX 20 |
76 | 76 | ||
@@ -87,23 +87,23 @@ | |||
87 | 87 | ||
88 | 88 | ||
89 | struct tag_name_st | 89 | struct tag_name_st |
90 | { | 90 | { |
91 | const char *strnam; | 91 | const char *strnam; |
92 | int len; | 92 | int len; |
93 | int tag; | 93 | int tag; |
94 | }; | 94 | }; |
95 | 95 | ||
96 | typedef struct | 96 | typedef struct |
97 | { | 97 | { |
98 | int exp_tag; | 98 | int exp_tag; |
99 | int exp_class; | 99 | int exp_class; |
100 | int exp_constructed; | 100 | int exp_constructed; |
101 | int exp_pad; | 101 | int exp_pad; |
102 | long exp_len; | 102 | long exp_len; |
103 | } tag_exp_type; | 103 | } tag_exp_type; |
104 | 104 | ||
105 | typedef struct | 105 | typedef struct |
106 | { | 106 | { |
107 | int imp_tag; | 107 | int imp_tag; |
108 | int imp_class; | 108 | int imp_class; |
109 | int utype; | 109 | int utype; |
@@ -111,7 +111,7 @@ typedef struct | |||
111 | const char *str; | 111 | const char *str; |
112 | tag_exp_type exp_list[ASN1_FLAG_EXP_MAX]; | 112 | tag_exp_type exp_list[ASN1_FLAG_EXP_MAX]; |
113 | int exp_count; | 113 | int exp_count; |
114 | } tag_exp_arg; | 114 | } tag_exp_arg; |
115 | 115 | ||
116 | static int bitstr_cb(const char *elem, int len, void *bitstr); | 116 | static int bitstr_cb(const char *elem, int len, void *bitstr); |
117 | static int asn1_cb(const char *elem, int len, void *bitstr); | 117 | static int asn1_cb(const char *elem, int len, void *bitstr); |
@@ -122,7 +122,7 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype); | |||
122 | static int asn1_str2tag(const char *tagstr, int len); | 122 | static int asn1_str2tag(const char *tagstr, int len); |
123 | 123 | ||
124 | ASN1_TYPE *ASN1_generate_nconf(char *str, CONF *nconf) | 124 | ASN1_TYPE *ASN1_generate_nconf(char *str, CONF *nconf) |
125 | { | 125 | { |
126 | X509V3_CTX cnf; | 126 | X509V3_CTX cnf; |
127 | 127 | ||
128 | if (!nconf) | 128 | if (!nconf) |
@@ -130,10 +130,10 @@ ASN1_TYPE *ASN1_generate_nconf(char *str, CONF *nconf) | |||
130 | 130 | ||
131 | X509V3_set_nconf(&cnf, nconf); | 131 | X509V3_set_nconf(&cnf, nconf); |
132 | return ASN1_generate_v3(str, &cnf); | 132 | return ASN1_generate_v3(str, &cnf); |
133 | } | 133 | } |
134 | 134 | ||
135 | ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf) | 135 | ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf) |
136 | { | 136 | { |
137 | ASN1_TYPE *ret; | 137 | ASN1_TYPE *ret; |
138 | tag_exp_arg asn1_tags; | 138 | tag_exp_arg asn1_tags; |
139 | tag_exp_type *etmp; | 139 | tag_exp_type *etmp; |
@@ -157,14 +157,14 @@ ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf) | |||
157 | return NULL; | 157 | return NULL; |
158 | 158 | ||
159 | if ((asn1_tags.utype == V_ASN1_SEQUENCE) || (asn1_tags.utype == V_ASN1_SET)) | 159 | if ((asn1_tags.utype == V_ASN1_SEQUENCE) || (asn1_tags.utype == V_ASN1_SET)) |
160 | { | 160 | { |
161 | if (!cnf) | 161 | if (!cnf) |
162 | { | 162 | { |
163 | ASN1err(ASN1_F_ASN1_GENERATE_V3, ASN1_R_SEQUENCE_OR_SET_NEEDS_CONFIG); | 163 | ASN1err(ASN1_F_ASN1_GENERATE_V3, ASN1_R_SEQUENCE_OR_SET_NEEDS_CONFIG); |
164 | return NULL; | 164 | return NULL; |
165 | } | ||
166 | ret = asn1_multi(asn1_tags.utype, asn1_tags.str, cnf); | ||
167 | } | 165 | } |
166 | ret = asn1_multi(asn1_tags.utype, asn1_tags.str, cnf); | ||
167 | } | ||
168 | else | 168 | else |
169 | ret = asn1_str2type(asn1_tags.str, asn1_tags.format, asn1_tags.utype); | 169 | ret = asn1_str2type(asn1_tags.str, asn1_tags.format, asn1_tags.utype); |
170 | 170 | ||
@@ -184,7 +184,7 @@ ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf) | |||
184 | 184 | ||
185 | /* Do we need IMPLICIT tagging? */ | 185 | /* Do we need IMPLICIT tagging? */ |
186 | if (asn1_tags.imp_tag != -1) | 186 | if (asn1_tags.imp_tag != -1) |
187 | { | 187 | { |
188 | /* If IMPLICIT we will replace the underlying tag */ | 188 | /* If IMPLICIT we will replace the underlying tag */ |
189 | /* Skip existing tag+len */ | 189 | /* Skip existing tag+len */ |
190 | r = ASN1_get_object(&cpy_start, &hdr_len, &hdr_tag, &hdr_class, cpy_len); | 190 | r = ASN1_get_object(&cpy_start, &hdr_len, &hdr_tag, &hdr_class, cpy_len); |
@@ -197,11 +197,11 @@ ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf) | |||
197 | * consistent. | 197 | * consistent. |
198 | */ | 198 | */ |
199 | if (r & 0x1) | 199 | if (r & 0x1) |
200 | { | 200 | { |
201 | /* Indefinite length constructed */ | 201 | /* Indefinite length constructed */ |
202 | hdr_constructed = 2; | 202 | hdr_constructed = 2; |
203 | hdr_len = 0; | 203 | hdr_len = 0; |
204 | } | 204 | } |
205 | else | 205 | else |
206 | /* Just retain constructed flag */ | 206 | /* Just retain constructed flag */ |
207 | hdr_constructed = r & V_ASN1_CONSTRUCTED; | 207 | hdr_constructed = r & V_ASN1_CONSTRUCTED; |
@@ -209,20 +209,20 @@ ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf) | |||
209 | * because it will mess up if indefinite length | 209 | * because it will mess up if indefinite length |
210 | */ | 210 | */ |
211 | len = ASN1_object_size(0, hdr_len, asn1_tags.imp_tag); | 211 | len = ASN1_object_size(0, hdr_len, asn1_tags.imp_tag); |
212 | } | 212 | } |
213 | else | 213 | else |
214 | len = cpy_len; | 214 | len = cpy_len; |
215 | 215 | ||
216 | /* Work out length in any EXPLICIT, starting from end */ | 216 | /* Work out length in any EXPLICIT, starting from end */ |
217 | 217 | ||
218 | for(i = 0, etmp = asn1_tags.exp_list + asn1_tags.exp_count - 1; i < asn1_tags.exp_count; i++, etmp--) | 218 | for(i = 0, etmp = asn1_tags.exp_list + asn1_tags.exp_count - 1; i < asn1_tags.exp_count; i++, etmp--) |
219 | { | 219 | { |
220 | /* Content length: number of content octets + any padding */ | 220 | /* Content length: number of content octets + any padding */ |
221 | len += etmp->exp_pad; | 221 | len += etmp->exp_pad; |
222 | etmp->exp_len = len; | 222 | etmp->exp_len = len; |
223 | /* Total object length: length including new header */ | 223 | /* Total object length: length including new header */ |
224 | len = ASN1_object_size(0, len, etmp->exp_tag); | 224 | len = ASN1_object_size(0, len, etmp->exp_tag); |
225 | } | 225 | } |
226 | 226 | ||
227 | /* Allocate buffer for new encoding */ | 227 | /* Allocate buffer for new encoding */ |
228 | 228 | ||
@@ -237,24 +237,24 @@ ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf) | |||
237 | /* Output explicit tags first */ | 237 | /* Output explicit tags first */ |
238 | 238 | ||
239 | for (i = 0, etmp = asn1_tags.exp_list; i < asn1_tags.exp_count; i++, etmp++) | 239 | for (i = 0, etmp = asn1_tags.exp_list; i < asn1_tags.exp_count; i++, etmp++) |
240 | { | 240 | { |
241 | ASN1_put_object(&p, etmp->exp_constructed, etmp->exp_len, | 241 | ASN1_put_object(&p, etmp->exp_constructed, etmp->exp_len, |
242 | etmp->exp_tag, etmp->exp_class); | 242 | etmp->exp_tag, etmp->exp_class); |
243 | if (etmp->exp_pad) | 243 | if (etmp->exp_pad) |
244 | *p++ = 0; | 244 | *p++ = 0; |
245 | } | 245 | } |
246 | 246 | ||
247 | /* If IMPLICIT, output tag */ | 247 | /* If IMPLICIT, output tag */ |
248 | 248 | ||
249 | if (asn1_tags.imp_tag != -1) | 249 | if (asn1_tags.imp_tag != -1) |
250 | { | 250 | { |
251 | if (asn1_tags.imp_class == V_ASN1_UNIVERSAL | 251 | if (asn1_tags.imp_class == V_ASN1_UNIVERSAL |
252 | && (asn1_tags.imp_tag == V_ASN1_SEQUENCE | 252 | && (asn1_tags.imp_tag == V_ASN1_SEQUENCE |
253 | || asn1_tags.imp_tag == V_ASN1_SET) ) | 253 | || asn1_tags.imp_tag == V_ASN1_SET) ) |
254 | hdr_constructed = V_ASN1_CONSTRUCTED; | 254 | hdr_constructed = V_ASN1_CONSTRUCTED; |
255 | ASN1_put_object(&p, hdr_constructed, hdr_len, | 255 | ASN1_put_object(&p, hdr_constructed, hdr_len, |
256 | asn1_tags.imp_tag, asn1_tags.imp_class); | 256 | asn1_tags.imp_tag, asn1_tags.imp_class); |
257 | } | 257 | } |
258 | 258 | ||
259 | /* Copy across original encoding */ | 259 | /* Copy across original encoding */ |
260 | memcpy(p, cpy_start, cpy_len); | 260 | memcpy(p, cpy_start, cpy_len); |
@@ -272,10 +272,10 @@ ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf) | |||
272 | 272 | ||
273 | return ret; | 273 | return ret; |
274 | 274 | ||
275 | } | 275 | } |
276 | 276 | ||
277 | static int asn1_cb(const char *elem, int len, void *bitstr) | 277 | static int asn1_cb(const char *elem, int len, void *bitstr) |
278 | { | 278 | { |
279 | tag_exp_arg *arg = bitstr; | 279 | tag_exp_arg *arg = bitstr; |
280 | int i; | 280 | int i; |
281 | int utype; | 281 | int utype; |
@@ -285,50 +285,50 @@ static int asn1_cb(const char *elem, int len, void *bitstr) | |||
285 | int tmp_tag, tmp_class; | 285 | int tmp_tag, tmp_class; |
286 | 286 | ||
287 | for(i = 0, p = elem; i < len; p++, i++) | 287 | for(i = 0, p = elem; i < len; p++, i++) |
288 | { | 288 | { |
289 | /* Look for the ':' in name value pairs */ | 289 | /* Look for the ':' in name value pairs */ |
290 | if (*p == ':') | 290 | if (*p == ':') |
291 | { | 291 | { |
292 | vstart = p + 1; | 292 | vstart = p + 1; |
293 | vlen = len - (vstart - elem); | 293 | vlen = len - (vstart - elem); |
294 | len = p - elem; | 294 | len = p - elem; |
295 | break; | 295 | break; |
296 | } | ||
297 | } | 296 | } |
297 | } | ||
298 | 298 | ||
299 | utype = asn1_str2tag(elem, len); | 299 | utype = asn1_str2tag(elem, len); |
300 | 300 | ||
301 | if (utype == -1) | 301 | if (utype == -1) |
302 | { | 302 | { |
303 | ASN1err(ASN1_F_ASN1_CB, ASN1_R_UNKNOWN_TAG); | 303 | ASN1err(ASN1_F_ASN1_CB, ASN1_R_UNKNOWN_TAG); |
304 | ERR_add_error_data(2, "tag=", elem); | 304 | ERR_add_error_data(2, "tag=", elem); |
305 | return -1; | 305 | return -1; |
306 | } | 306 | } |
307 | 307 | ||
308 | /* If this is not a modifier mark end of string and exit */ | 308 | /* If this is not a modifier mark end of string and exit */ |
309 | if (!(utype & ASN1_GEN_FLAG)) | 309 | if (!(utype & ASN1_GEN_FLAG)) |
310 | { | 310 | { |
311 | arg->utype = utype; | 311 | arg->utype = utype; |
312 | arg->str = vstart; | 312 | arg->str = vstart; |
313 | /* If no value and not end of string, error */ | 313 | /* If no value and not end of string, error */ |
314 | if (!vstart && elem[len]) | 314 | if (!vstart && elem[len]) |
315 | { | 315 | { |
316 | ASN1err(ASN1_F_ASN1_CB, ASN1_R_MISSING_VALUE); | 316 | ASN1err(ASN1_F_ASN1_CB, ASN1_R_MISSING_VALUE); |
317 | return -1; | 317 | return -1; |
318 | } | ||
319 | return 0; | ||
320 | } | 318 | } |
319 | return 0; | ||
320 | } | ||
321 | 321 | ||
322 | switch(utype) | 322 | switch(utype) |
323 | { | 323 | { |
324 | 324 | ||
325 | case ASN1_GEN_FLAG_IMP: | 325 | case ASN1_GEN_FLAG_IMP: |
326 | /* Check for illegal multiple IMPLICIT tagging */ | 326 | /* Check for illegal multiple IMPLICIT tagging */ |
327 | if (arg->imp_tag != -1) | 327 | if (arg->imp_tag != -1) |
328 | { | 328 | { |
329 | ASN1err(ASN1_F_ASN1_CB, ASN1_R_ILLEGAL_NESTED_TAGGING); | 329 | ASN1err(ASN1_F_ASN1_CB, ASN1_R_ILLEGAL_NESTED_TAGGING); |
330 | return -1; | 330 | return -1; |
331 | } | 331 | } |
332 | if (!parse_tagging(vstart, vlen, &arg->imp_tag, &arg->imp_class)) | 332 | if (!parse_tagging(vstart, vlen, &arg->imp_tag, &arg->imp_class)) |
333 | return -1; | 333 | return -1; |
334 | break; | 334 | break; |
@@ -371,20 +371,20 @@ static int asn1_cb(const char *elem, int len, void *bitstr) | |||
371 | else if (!strncmp(vstart, "BITLIST", 7)) | 371 | else if (!strncmp(vstart, "BITLIST", 7)) |
372 | arg->format = ASN1_GEN_FORMAT_BITLIST; | 372 | arg->format = ASN1_GEN_FORMAT_BITLIST; |
373 | else | 373 | else |
374 | { | 374 | { |
375 | ASN1err(ASN1_F_ASN1_CB, ASN1_R_UNKOWN_FORMAT); | 375 | ASN1err(ASN1_F_ASN1_CB, ASN1_R_UNKOWN_FORMAT); |
376 | return -1; | 376 | return -1; |
377 | } | 377 | } |
378 | break; | 378 | break; |
379 | 379 | ||
380 | } | 380 | } |
381 | 381 | ||
382 | return 1; | 382 | return 1; |
383 | 383 | ||
384 | } | 384 | } |
385 | 385 | ||
386 | static int parse_tagging(const char *vstart, int vlen, int *ptag, int *pclass) | 386 | static int parse_tagging(const char *vstart, int vlen, int *ptag, int *pclass) |
387 | { | 387 | { |
388 | char erch[2]; | 388 | char erch[2]; |
389 | long tag_num; | 389 | long tag_num; |
390 | char *eptr; | 390 | char *eptr; |
@@ -395,10 +395,10 @@ static int parse_tagging(const char *vstart, int vlen, int *ptag, int *pclass) | |||
395 | if (eptr && *eptr && (eptr > vstart + vlen)) | 395 | if (eptr && *eptr && (eptr > vstart + vlen)) |
396 | return 0; | 396 | return 0; |
397 | if (tag_num < 0) | 397 | if (tag_num < 0) |
398 | { | 398 | { |
399 | ASN1err(ASN1_F_PARSE_TAGGING, ASN1_R_INVALID_NUMBER); | 399 | ASN1err(ASN1_F_PARSE_TAGGING, ASN1_R_INVALID_NUMBER); |
400 | return 0; | 400 | return 0; |
401 | } | 401 | } |
402 | *ptag = tag_num; | 402 | *ptag = tag_num; |
403 | /* If we have non numeric characters, parse them */ | 403 | /* If we have non numeric characters, parse them */ |
404 | if (eptr) | 404 | if (eptr) |
@@ -406,9 +406,9 @@ static int parse_tagging(const char *vstart, int vlen, int *ptag, int *pclass) | |||
406 | else | 406 | else |
407 | vlen = 0; | 407 | vlen = 0; |
408 | if (vlen) | 408 | if (vlen) |
409 | { | 409 | { |
410 | switch (*eptr) | 410 | switch (*eptr) |
411 | { | 411 | { |
412 | 412 | ||
413 | case 'U': | 413 | case 'U': |
414 | *pclass = V_ASN1_UNIVERSAL; | 414 | *pclass = V_ASN1_UNIVERSAL; |
@@ -434,19 +434,19 @@ static int parse_tagging(const char *vstart, int vlen, int *ptag, int *pclass) | |||
434 | return 0; | 434 | return 0; |
435 | break; | 435 | break; |
436 | 436 | ||
437 | } | ||
438 | } | 437 | } |
438 | } | ||
439 | else | 439 | else |
440 | *pclass = V_ASN1_CONTEXT_SPECIFIC; | 440 | *pclass = V_ASN1_CONTEXT_SPECIFIC; |
441 | 441 | ||
442 | return 1; | 442 | return 1; |
443 | 443 | ||
444 | } | 444 | } |
445 | 445 | ||
446 | /* Handle multiple types: SET and SEQUENCE */ | 446 | /* Handle multiple types: SET and SEQUENCE */ |
447 | 447 | ||
448 | static ASN1_TYPE *asn1_multi(int utype, const char *section, X509V3_CTX *cnf) | 448 | static ASN1_TYPE *asn1_multi(int utype, const char *section, X509V3_CTX *cnf) |
449 | { | 449 | { |
450 | ASN1_TYPE *ret = NULL; | 450 | ASN1_TYPE *ret = NULL; |
451 | STACK_OF(ASN1_TYPE) *sk = NULL; | 451 | STACK_OF(ASN1_TYPE) *sk = NULL; |
452 | STACK_OF(CONF_VALUE) *sect = NULL; | 452 | STACK_OF(CONF_VALUE) *sect = NULL; |
@@ -457,21 +457,21 @@ static ASN1_TYPE *asn1_multi(int utype, const char *section, X509V3_CTX *cnf) | |||
457 | if (!sk) | 457 | if (!sk) |
458 | goto bad; | 458 | goto bad; |
459 | if (section) | 459 | if (section) |
460 | { | 460 | { |
461 | if (!cnf) | 461 | if (!cnf) |
462 | goto bad; | 462 | goto bad; |
463 | sect = X509V3_get_section(cnf, (char *)section); | 463 | sect = X509V3_get_section(cnf, (char *)section); |
464 | if (!sect) | 464 | if (!sect) |
465 | goto bad; | 465 | goto bad; |
466 | for (i = 0; i < sk_CONF_VALUE_num(sect); i++) | 466 | for (i = 0; i < sk_CONF_VALUE_num(sect); i++) |
467 | { | 467 | { |
468 | ASN1_TYPE *typ = ASN1_generate_v3(sk_CONF_VALUE_value(sect, i)->value, cnf); | 468 | ASN1_TYPE *typ = ASN1_generate_v3(sk_CONF_VALUE_value(sect, i)->value, cnf); |
469 | if (!typ) | 469 | if (!typ) |
470 | goto bad; | 470 | goto bad; |
471 | if (!sk_ASN1_TYPE_push(sk, typ)) | 471 | if (!sk_ASN1_TYPE_push(sk, typ)) |
472 | goto bad; | 472 | goto bad; |
473 | } | ||
474 | } | 473 | } |
474 | } | ||
475 | 475 | ||
476 | /* Now we has a STACK of the components, convert to the correct form */ | 476 | /* Now we has a STACK of the components, convert to the correct form */ |
477 | 477 | ||
@@ -507,23 +507,23 @@ static ASN1_TYPE *asn1_multi(int utype, const char *section, X509V3_CTX *cnf) | |||
507 | X509V3_section_free(cnf, sect); | 507 | X509V3_section_free(cnf, sect); |
508 | 508 | ||
509 | return ret; | 509 | return ret; |
510 | } | 510 | } |
511 | 511 | ||
512 | static int append_exp(tag_exp_arg *arg, int exp_tag, int exp_class, int exp_constructed, int exp_pad, int imp_ok) | 512 | static int append_exp(tag_exp_arg *arg, int exp_tag, int exp_class, int exp_constructed, int exp_pad, int imp_ok) |
513 | { | 513 | { |
514 | tag_exp_type *exp_tmp; | 514 | tag_exp_type *exp_tmp; |
515 | /* Can only have IMPLICIT if permitted */ | 515 | /* Can only have IMPLICIT if permitted */ |
516 | if ((arg->imp_tag != -1) && !imp_ok) | 516 | if ((arg->imp_tag != -1) && !imp_ok) |
517 | { | 517 | { |
518 | ASN1err(ASN1_F_APPEND_EXP, ASN1_R_ILLEGAL_IMPLICIT_TAG); | 518 | ASN1err(ASN1_F_APPEND_EXP, ASN1_R_ILLEGAL_IMPLICIT_TAG); |
519 | return 0; | 519 | return 0; |
520 | } | 520 | } |
521 | 521 | ||
522 | if (arg->exp_count == ASN1_FLAG_EXP_MAX) | 522 | if (arg->exp_count == ASN1_FLAG_EXP_MAX) |
523 | { | 523 | { |
524 | ASN1err(ASN1_F_APPEND_EXP, ASN1_R_DEPTH_EXCEEDED); | 524 | ASN1err(ASN1_F_APPEND_EXP, ASN1_R_DEPTH_EXCEEDED); |
525 | return 0; | 525 | return 0; |
526 | } | 526 | } |
527 | 527 | ||
528 | exp_tmp = &arg->exp_list[arg->exp_count++]; | 528 | exp_tmp = &arg->exp_list[arg->exp_count++]; |
529 | 529 | ||
@@ -531,26 +531,26 @@ static int append_exp(tag_exp_arg *arg, int exp_tag, int exp_class, int exp_cons | |||
531 | * reset implicit tag since it has been used. | 531 | * reset implicit tag since it has been used. |
532 | */ | 532 | */ |
533 | if (arg->imp_tag != -1) | 533 | if (arg->imp_tag != -1) |
534 | { | 534 | { |
535 | exp_tmp->exp_tag = arg->imp_tag; | 535 | exp_tmp->exp_tag = arg->imp_tag; |
536 | exp_tmp->exp_class = arg->imp_class; | 536 | exp_tmp->exp_class = arg->imp_class; |
537 | arg->imp_tag = -1; | 537 | arg->imp_tag = -1; |
538 | arg->imp_class = -1; | 538 | arg->imp_class = -1; |
539 | } | 539 | } |
540 | else | 540 | else |
541 | { | 541 | { |
542 | exp_tmp->exp_tag = exp_tag; | 542 | exp_tmp->exp_tag = exp_tag; |
543 | exp_tmp->exp_class = exp_class; | 543 | exp_tmp->exp_class = exp_class; |
544 | } | 544 | } |
545 | exp_tmp->exp_constructed = exp_constructed; | 545 | exp_tmp->exp_constructed = exp_constructed; |
546 | exp_tmp->exp_pad = exp_pad; | 546 | exp_tmp->exp_pad = exp_pad; |
547 | 547 | ||
548 | return 1; | 548 | return 1; |
549 | } | 549 | } |
550 | 550 | ||
551 | 551 | ||
552 | static int asn1_str2tag(const char *tagstr, int len) | 552 | static int asn1_str2tag(const char *tagstr, int len) |
553 | { | 553 | { |
554 | unsigned int i; | 554 | unsigned int i; |
555 | static const struct tag_name_st *tntmp, tnst [] = { | 555 | static const struct tag_name_st *tntmp, tnst [] = { |
556 | ASN1_GEN_STR("BOOL", V_ASN1_BOOLEAN), | 556 | ASN1_GEN_STR("BOOL", V_ASN1_BOOLEAN), |
@@ -611,23 +611,23 @@ static int asn1_str2tag(const char *tagstr, int len) | |||
611 | ASN1_GEN_STR("BITWRAP", ASN1_GEN_FLAG_BITWRAP), | 611 | ASN1_GEN_STR("BITWRAP", ASN1_GEN_FLAG_BITWRAP), |
612 | ASN1_GEN_STR("FORM", ASN1_GEN_FLAG_FORMAT), | 612 | ASN1_GEN_STR("FORM", ASN1_GEN_FLAG_FORMAT), |
613 | ASN1_GEN_STR("FORMAT", ASN1_GEN_FLAG_FORMAT), | 613 | ASN1_GEN_STR("FORMAT", ASN1_GEN_FLAG_FORMAT), |
614 | }; | 614 | }; |
615 | 615 | ||
616 | if (len == -1) | 616 | if (len == -1) |
617 | len = strlen(tagstr); | 617 | len = strlen(tagstr); |
618 | 618 | ||
619 | tntmp = tnst; | 619 | tntmp = tnst; |
620 | for (i = 0; i < sizeof(tnst) / sizeof(struct tag_name_st); i++, tntmp++) | 620 | for (i = 0; i < sizeof(tnst) / sizeof(struct tag_name_st); i++, tntmp++) |
621 | { | 621 | { |
622 | if ((len == tntmp->len) && !strncmp(tntmp->strnam, tagstr, len)) | 622 | if ((len == tntmp->len) && !strncmp(tntmp->strnam, tagstr, len)) |
623 | return tntmp->tag; | 623 | return tntmp->tag; |
624 | } | 624 | } |
625 | 625 | ||
626 | return -1; | 626 | return -1; |
627 | } | 627 | } |
628 | 628 | ||
629 | static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype) | 629 | static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype) |
630 | { | 630 | { |
631 | ASN1_TYPE *atmp = NULL; | 631 | ASN1_TYPE *atmp = NULL; |
632 | 632 | ||
633 | CONF_VALUE vtmp; | 633 | CONF_VALUE vtmp; |
@@ -638,91 +638,91 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype) | |||
638 | int no_unused = 1; | 638 | int no_unused = 1; |
639 | 639 | ||
640 | if (!(atmp = ASN1_TYPE_new())) | 640 | if (!(atmp = ASN1_TYPE_new())) |
641 | { | 641 | { |
642 | ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE); | 642 | ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE); |
643 | return NULL; | 643 | return NULL; |
644 | } | 644 | } |
645 | 645 | ||
646 | if (!str) | 646 | if (!str) |
647 | str = ""; | 647 | str = ""; |
648 | 648 | ||
649 | switch(utype) | 649 | switch(utype) |
650 | { | 650 | { |
651 | 651 | ||
652 | case V_ASN1_NULL: | 652 | case V_ASN1_NULL: |
653 | if (str && *str) | 653 | if (str && *str) |
654 | { | 654 | { |
655 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_NULL_VALUE); | 655 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_NULL_VALUE); |
656 | goto bad_form; | 656 | goto bad_form; |
657 | } | 657 | } |
658 | break; | 658 | break; |
659 | 659 | ||
660 | case V_ASN1_BOOLEAN: | 660 | case V_ASN1_BOOLEAN: |
661 | if (format != ASN1_GEN_FORMAT_ASCII) | 661 | if (format != ASN1_GEN_FORMAT_ASCII) |
662 | { | 662 | { |
663 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_NOT_ASCII_FORMAT); | 663 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_NOT_ASCII_FORMAT); |
664 | goto bad_form; | 664 | goto bad_form; |
665 | } | 665 | } |
666 | vtmp.name = NULL; | 666 | vtmp.name = NULL; |
667 | vtmp.section = NULL; | 667 | vtmp.section = NULL; |
668 | vtmp.value = (char *)str; | 668 | vtmp.value = (char *)str; |
669 | if (!X509V3_get_value_bool(&vtmp, &atmp->value.boolean)) | 669 | if (!X509V3_get_value_bool(&vtmp, &atmp->value.boolean)) |
670 | { | 670 | { |
671 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_BOOLEAN); | 671 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_BOOLEAN); |
672 | goto bad_str; | 672 | goto bad_str; |
673 | } | 673 | } |
674 | break; | 674 | break; |
675 | 675 | ||
676 | case V_ASN1_INTEGER: | 676 | case V_ASN1_INTEGER: |
677 | case V_ASN1_ENUMERATED: | 677 | case V_ASN1_ENUMERATED: |
678 | if (format != ASN1_GEN_FORMAT_ASCII) | 678 | if (format != ASN1_GEN_FORMAT_ASCII) |
679 | { | 679 | { |
680 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_INTEGER_NOT_ASCII_FORMAT); | 680 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_INTEGER_NOT_ASCII_FORMAT); |
681 | goto bad_form; | 681 | goto bad_form; |
682 | } | 682 | } |
683 | if (!(atmp->value.integer = s2i_ASN1_INTEGER(NULL, (char *)str))) | 683 | if (!(atmp->value.integer = s2i_ASN1_INTEGER(NULL, (char *)str))) |
684 | { | 684 | { |
685 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_INTEGER); | 685 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_INTEGER); |
686 | goto bad_str; | 686 | goto bad_str; |
687 | } | 687 | } |
688 | break; | 688 | break; |
689 | 689 | ||
690 | case V_ASN1_OBJECT: | 690 | case V_ASN1_OBJECT: |
691 | if (format != ASN1_GEN_FORMAT_ASCII) | 691 | if (format != ASN1_GEN_FORMAT_ASCII) |
692 | { | 692 | { |
693 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_OBJECT_NOT_ASCII_FORMAT); | 693 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_OBJECT_NOT_ASCII_FORMAT); |
694 | goto bad_form; | 694 | goto bad_form; |
695 | } | 695 | } |
696 | if (!(atmp->value.object = OBJ_txt2obj(str, 0))) | 696 | if (!(atmp->value.object = OBJ_txt2obj(str, 0))) |
697 | { | 697 | { |
698 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_OBJECT); | 698 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_OBJECT); |
699 | goto bad_str; | 699 | goto bad_str; |
700 | } | 700 | } |
701 | break; | 701 | break; |
702 | 702 | ||
703 | case V_ASN1_UTCTIME: | 703 | case V_ASN1_UTCTIME: |
704 | case V_ASN1_GENERALIZEDTIME: | 704 | case V_ASN1_GENERALIZEDTIME: |
705 | if (format != ASN1_GEN_FORMAT_ASCII) | 705 | if (format != ASN1_GEN_FORMAT_ASCII) |
706 | { | 706 | { |
707 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_TIME_NOT_ASCII_FORMAT); | 707 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_TIME_NOT_ASCII_FORMAT); |
708 | goto bad_form; | 708 | goto bad_form; |
709 | } | 709 | } |
710 | if (!(atmp->value.asn1_string = ASN1_STRING_new())) | 710 | if (!(atmp->value.asn1_string = ASN1_STRING_new())) |
711 | { | 711 | { |
712 | ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE); | 712 | ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE); |
713 | goto bad_str; | 713 | goto bad_str; |
714 | } | 714 | } |
715 | if (!ASN1_STRING_set(atmp->value.asn1_string, str, -1)) | 715 | if (!ASN1_STRING_set(atmp->value.asn1_string, str, -1)) |
716 | { | 716 | { |
717 | ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE); | 717 | ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE); |
718 | goto bad_str; | 718 | goto bad_str; |
719 | } | 719 | } |
720 | atmp->value.asn1_string->type = utype; | 720 | atmp->value.asn1_string->type = utype; |
721 | if (!ASN1_TIME_check(atmp->value.asn1_string)) | 721 | if (!ASN1_TIME_check(atmp->value.asn1_string)) |
722 | { | 722 | { |
723 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_TIME_VALUE); | 723 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_TIME_VALUE); |
724 | goto bad_str; | 724 | goto bad_str; |
725 | } | 725 | } |
726 | 726 | ||
727 | break; | 727 | break; |
728 | 728 | ||
@@ -741,18 +741,18 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype) | |||
741 | else if (format == ASN1_GEN_FORMAT_UTF8) | 741 | else if (format == ASN1_GEN_FORMAT_UTF8) |
742 | format = MBSTRING_UTF8; | 742 | format = MBSTRING_UTF8; |
743 | else | 743 | else |
744 | { | 744 | { |
745 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_FORMAT); | 745 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_FORMAT); |
746 | goto bad_form; | 746 | goto bad_form; |
747 | } | 747 | } |
748 | 748 | ||
749 | 749 | ||
750 | if (ASN1_mbstring_copy(&atmp->value.asn1_string, (unsigned char *)str, | 750 | if (ASN1_mbstring_copy(&atmp->value.asn1_string, (unsigned char *)str, |
751 | -1, format, ASN1_tag2bit(utype)) <= 0) | 751 | -1, format, ASN1_tag2bit(utype)) <= 0) |
752 | { | 752 | { |
753 | ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE); | 753 | ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE); |
754 | goto bad_str; | 754 | goto bad_str; |
755 | } | 755 | } |
756 | 756 | ||
757 | 757 | ||
758 | break; | 758 | break; |
@@ -762,50 +762,50 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype) | |||
762 | case V_ASN1_OCTET_STRING: | 762 | case V_ASN1_OCTET_STRING: |
763 | 763 | ||
764 | if (!(atmp->value.asn1_string = ASN1_STRING_new())) | 764 | if (!(atmp->value.asn1_string = ASN1_STRING_new())) |
765 | { | 765 | { |
766 | ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE); | 766 | ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE); |
767 | goto bad_form; | 767 | goto bad_form; |
768 | } | 768 | } |
769 | 769 | ||
770 | if (format == ASN1_GEN_FORMAT_HEX) | 770 | if (format == ASN1_GEN_FORMAT_HEX) |
771 | { | 771 | { |
772 | 772 | ||
773 | if (!(rdata = string_to_hex((char *)str, &rdlen))) | 773 | if (!(rdata = string_to_hex((char *)str, &rdlen))) |
774 | { | 774 | { |
775 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_HEX); | 775 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_HEX); |
776 | goto bad_str; | 776 | goto bad_str; |
777 | } | 777 | } |
778 | 778 | ||
779 | atmp->value.asn1_string->data = rdata; | 779 | atmp->value.asn1_string->data = rdata; |
780 | atmp->value.asn1_string->length = rdlen; | 780 | atmp->value.asn1_string->length = rdlen; |
781 | atmp->value.asn1_string->type = utype; | 781 | atmp->value.asn1_string->type = utype; |
782 | 782 | ||
783 | } | 783 | } |
784 | else if (format == ASN1_GEN_FORMAT_ASCII) | 784 | else if (format == ASN1_GEN_FORMAT_ASCII) |
785 | ASN1_STRING_set(atmp->value.asn1_string, str, -1); | 785 | ASN1_STRING_set(atmp->value.asn1_string, str, -1); |
786 | else if ((format == ASN1_GEN_FORMAT_BITLIST) && (utype == V_ASN1_BIT_STRING)) | 786 | else if ((format == ASN1_GEN_FORMAT_BITLIST) && (utype == V_ASN1_BIT_STRING)) |
787 | { | 787 | { |
788 | if (!CONF_parse_list(str, ',', 1, bitstr_cb, atmp->value.bit_string)) | 788 | if (!CONF_parse_list(str, ',', 1, bitstr_cb, atmp->value.bit_string)) |
789 | { | 789 | { |
790 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_LIST_ERROR); | 790 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_LIST_ERROR); |
791 | goto bad_str; | 791 | goto bad_str; |
792 | } | 792 | } |
793 | no_unused = 0; | 793 | no_unused = 0; |
794 | 794 | ||
795 | } | 795 | } |
796 | else | 796 | else |
797 | { | 797 | { |
798 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_BITSTRING_FORMAT); | 798 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_BITSTRING_FORMAT); |
799 | goto bad_form; | 799 | goto bad_form; |
800 | } | 800 | } |
801 | 801 | ||
802 | if ((utype == V_ASN1_BIT_STRING) && no_unused) | 802 | if ((utype == V_ASN1_BIT_STRING) && no_unused) |
803 | { | 803 | { |
804 | atmp->value.asn1_string->flags | 804 | atmp->value.asn1_string->flags |
805 | &= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); | 805 | &= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); |
806 | atmp->value.asn1_string->flags | 806 | atmp->value.asn1_string->flags |
807 | |= ASN1_STRING_FLAG_BITS_LEFT; | 807 | |= ASN1_STRING_FLAG_BITS_LEFT; |
808 | } | 808 | } |
809 | 809 | ||
810 | 810 | ||
811 | break; | 811 | break; |
@@ -814,7 +814,7 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype) | |||
814 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_UNSUPPORTED_TYPE); | 814 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_UNSUPPORTED_TYPE); |
815 | goto bad_str; | 815 | goto bad_str; |
816 | break; | 816 | break; |
817 | } | 817 | } |
818 | 818 | ||
819 | 819 | ||
820 | atmp->type = utype; | 820 | atmp->type = utype; |
@@ -828,10 +828,10 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype) | |||
828 | ASN1_TYPE_free(atmp); | 828 | ASN1_TYPE_free(atmp); |
829 | return NULL; | 829 | return NULL; |
830 | 830 | ||
831 | } | 831 | } |
832 | 832 | ||
833 | static int bitstr_cb(const char *elem, int len, void *bitstr) | 833 | static int bitstr_cb(const char *elem, int len, void *bitstr) |
834 | { | 834 | { |
835 | long bitnum; | 835 | long bitnum; |
836 | char *eptr; | 836 | char *eptr; |
837 | if (!elem) | 837 | if (!elem) |
@@ -840,15 +840,15 @@ static int bitstr_cb(const char *elem, int len, void *bitstr) | |||
840 | if (eptr && *eptr && (eptr != elem + len)) | 840 | if (eptr && *eptr && (eptr != elem + len)) |
841 | return 0; | 841 | return 0; |
842 | if (bitnum < 0) | 842 | if (bitnum < 0) |
843 | { | 843 | { |
844 | ASN1err(ASN1_F_BITSTR_CB, ASN1_R_INVALID_NUMBER); | 844 | ASN1err(ASN1_F_BITSTR_CB, ASN1_R_INVALID_NUMBER); |
845 | return 0; | 845 | return 0; |
846 | } | 846 | } |
847 | if (!ASN1_BIT_STRING_set_bit(bitstr, bitnum, 1)) | 847 | if (!ASN1_BIT_STRING_set_bit(bitstr, bitnum, 1)) |
848 | { | 848 | { |
849 | ASN1err(ASN1_F_BITSTR_CB, ERR_R_MALLOC_FAILURE); | 849 | ASN1err(ASN1_F_BITSTR_CB, ERR_R_MALLOC_FAILURE); |
850 | return 0; | 850 | return 0; |
851 | } | ||
852 | return 1; | ||
853 | } | 851 | } |
852 | return 1; | ||
853 | } | ||
854 | 854 | ||
diff --git a/src/lib/libssl/src/crypto/asn1/asn1_lib.c b/src/lib/libssl/src/crypto/asn1/asn1_lib.c index 7b06b6fdc8..6ec383859f 100644 --- a/src/lib/libssl/src/crypto/asn1/asn1_lib.c +++ b/src/lib/libssl/src/crypto/asn1/asn1_lib.c | |||
@@ -67,33 +67,33 @@ static void asn1_put_length(unsigned char **pp, int length); | |||
67 | const char ASN1_version[]="ASN.1" OPENSSL_VERSION_PTEXT; | 67 | const char ASN1_version[]="ASN.1" OPENSSL_VERSION_PTEXT; |
68 | 68 | ||
69 | static int _asn1_check_infinite_end(const unsigned char **p, long len) | 69 | static int _asn1_check_infinite_end(const unsigned char **p, long len) |
70 | { | 70 | { |
71 | /* If there is 0 or 1 byte left, the length check should pick | 71 | /* If there is 0 or 1 byte left, the length check should pick |
72 | * things up */ | 72 | * things up */ |
73 | if (len <= 0) | 73 | if (len <= 0) |
74 | return(1); | 74 | return(1); |
75 | else if ((len >= 2) && ((*p)[0] == 0) && ((*p)[1] == 0)) | 75 | else if ((len >= 2) && ((*p)[0] == 0) && ((*p)[1] == 0)) |
76 | { | 76 | { |
77 | (*p)+=2; | 77 | (*p)+=2; |
78 | return(1); | 78 | return(1); |
79 | } | ||
80 | return(0); | ||
81 | } | 79 | } |
80 | return(0); | ||
81 | } | ||
82 | 82 | ||
83 | int ASN1_check_infinite_end(unsigned char **p, long len) | 83 | int ASN1_check_infinite_end(unsigned char **p, long len) |
84 | { | 84 | { |
85 | return _asn1_check_infinite_end((const unsigned char **)p, len); | 85 | return _asn1_check_infinite_end((const unsigned char **)p, len); |
86 | } | 86 | } |
87 | 87 | ||
88 | int ASN1_const_check_infinite_end(const unsigned char **p, long len) | 88 | int ASN1_const_check_infinite_end(const unsigned char **p, long len) |
89 | { | 89 | { |
90 | return _asn1_check_infinite_end(p, len); | 90 | return _asn1_check_infinite_end(p, len); |
91 | } | 91 | } |
92 | 92 | ||
93 | 93 | ||
94 | int ASN1_get_object(const unsigned char **pp, long *plength, int *ptag, | 94 | int ASN1_get_object(const unsigned char **pp, long *plength, int *ptag, |
95 | int *pclass, long omax) | 95 | int *pclass, long omax) |
96 | { | 96 | { |
97 | int i,ret; | 97 | int i,ret; |
98 | long l; | 98 | long l; |
99 | const unsigned char *p= *pp; | 99 | const unsigned char *p= *pp; |
@@ -105,28 +105,28 @@ int ASN1_get_object(const unsigned char **pp, long *plength, int *ptag, | |||
105 | xclass=(*p&V_ASN1_PRIVATE); | 105 | xclass=(*p&V_ASN1_PRIVATE); |
106 | i= *p&V_ASN1_PRIMITIVE_TAG; | 106 | i= *p&V_ASN1_PRIMITIVE_TAG; |
107 | if (i == V_ASN1_PRIMITIVE_TAG) | 107 | if (i == V_ASN1_PRIMITIVE_TAG) |
108 | { /* high-tag */ | 108 | { /* high-tag */ |
109 | p++; | 109 | p++; |
110 | if (--max == 0) goto err; | 110 | if (--max == 0) goto err; |
111 | l=0; | 111 | l=0; |
112 | while (*p&0x80) | 112 | while (*p&0x80) |
113 | { | 113 | { |
114 | l<<=7L; | 114 | l<<=7L; |
115 | l|= *(p++)&0x7f; | 115 | l|= *(p++)&0x7f; |
116 | if (--max == 0) goto err; | 116 | if (--max == 0) goto err; |
117 | if (l > (INT_MAX >> 7L)) goto err; | 117 | if (l > (INT_MAX >> 7L)) goto err; |
118 | } | 118 | } |
119 | l<<=7L; | 119 | l<<=7L; |
120 | l|= *(p++)&0x7f; | 120 | l|= *(p++)&0x7f; |
121 | tag=(int)l; | 121 | tag=(int)l; |
122 | if (--max == 0) goto err; | 122 | if (--max == 0) goto err; |
123 | } | 123 | } |
124 | else | 124 | else |
125 | { | 125 | { |
126 | tag=i; | 126 | tag=i; |
127 | p++; | 127 | p++; |
128 | if (--max == 0) goto err; | 128 | if (--max == 0) goto err; |
129 | } | 129 | } |
130 | *ptag=tag; | 130 | *ptag=tag; |
131 | *pclass=xclass; | 131 | *pclass=xclass; |
132 | if (!asn1_get_length(&p,&inf,plength,(int)max)) goto err; | 132 | if (!asn1_get_length(&p,&inf,plength,(int)max)) goto err; |
@@ -138,63 +138,63 @@ int ASN1_get_object(const unsigned char **pp, long *plength, int *ptag, | |||
138 | 138 | ||
139 | #endif | 139 | #endif |
140 | if (*plength > (omax - (p - *pp))) | 140 | if (*plength > (omax - (p - *pp))) |
141 | { | 141 | { |
142 | ASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_TOO_LONG); | 142 | ASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_TOO_LONG); |
143 | /* Set this so that even if things are not long enough | 143 | /* Set this so that even if things are not long enough |
144 | * the values are set correctly */ | 144 | * the values are set correctly */ |
145 | ret|=0x80; | 145 | ret|=0x80; |
146 | } | 146 | } |
147 | *pp=p; | 147 | *pp=p; |
148 | return(ret|inf); | 148 | return(ret|inf); |
149 | err: | 149 | err: |
150 | ASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_HEADER_TOO_LONG); | 150 | ASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_HEADER_TOO_LONG); |
151 | return(0x80); | 151 | return(0x80); |
152 | } | 152 | } |
153 | 153 | ||
154 | static int asn1_get_length(const unsigned char **pp, int *inf, long *rl, int max) | 154 | static int asn1_get_length(const unsigned char **pp, int *inf, long *rl, int max) |
155 | { | 155 | { |
156 | const unsigned char *p= *pp; | 156 | const unsigned char *p= *pp; |
157 | unsigned long ret=0; | 157 | unsigned long ret=0; |
158 | unsigned int i; | 158 | unsigned int i; |
159 | 159 | ||
160 | if (max-- < 1) return(0); | 160 | if (max-- < 1) return(0); |
161 | if (*p == 0x80) | 161 | if (*p == 0x80) |
162 | { | 162 | { |
163 | *inf=1; | 163 | *inf=1; |
164 | ret=0; | 164 | ret=0; |
165 | p++; | 165 | p++; |
166 | } | 166 | } |
167 | else | 167 | else |
168 | { | 168 | { |
169 | *inf=0; | 169 | *inf=0; |
170 | i= *p&0x7f; | 170 | i= *p&0x7f; |
171 | if (*(p++) & 0x80) | 171 | if (*(p++) & 0x80) |
172 | { | 172 | { |
173 | if (i > sizeof(long)) | 173 | if (i > sizeof(long)) |
174 | return 0; | 174 | return 0; |
175 | if (max-- == 0) return(0); | 175 | if (max-- == 0) return(0); |
176 | while (i-- > 0) | 176 | while (i-- > 0) |
177 | { | 177 | { |
178 | ret<<=8L; | 178 | ret<<=8L; |
179 | ret|= *(p++); | 179 | ret|= *(p++); |
180 | if (max-- == 0) return(0); | 180 | if (max-- == 0) return(0); |
181 | } | ||
182 | } | 181 | } |
182 | } | ||
183 | else | 183 | else |
184 | ret=i; | 184 | ret=i; |
185 | } | 185 | } |
186 | if (ret > LONG_MAX) | 186 | if (ret > LONG_MAX) |
187 | return 0; | 187 | return 0; |
188 | *pp=p; | 188 | *pp=p; |
189 | *rl=(long)ret; | 189 | *rl=(long)ret; |
190 | return(1); | 190 | return(1); |
191 | } | 191 | } |
192 | 192 | ||
193 | /* class 0 is constructed | 193 | /* class 0 is constructed |
194 | * constructed == 2 for indefinite length constructed */ | 194 | * constructed == 2 for indefinite length constructed */ |
195 | void ASN1_put_object(unsigned char **pp, int constructed, int length, int tag, | 195 | void ASN1_put_object(unsigned char **pp, int constructed, int length, int tag, |
196 | int xclass) | 196 | int xclass) |
197 | { | 197 | { |
198 | unsigned char *p= *pp; | 198 | unsigned char *p= *pp; |
199 | int i, ttag; | 199 | int i, ttag; |
200 | 200 | ||
@@ -203,145 +203,145 @@ void ASN1_put_object(unsigned char **pp, int constructed, int length, int tag, | |||
203 | if (tag < 31) | 203 | if (tag < 31) |
204 | *(p++)=i|(tag&V_ASN1_PRIMITIVE_TAG); | 204 | *(p++)=i|(tag&V_ASN1_PRIMITIVE_TAG); |
205 | else | 205 | else |
206 | { | 206 | { |
207 | *(p++)=i|V_ASN1_PRIMITIVE_TAG; | 207 | *(p++)=i|V_ASN1_PRIMITIVE_TAG; |
208 | for(i = 0, ttag = tag; ttag > 0; i++) ttag >>=7; | 208 | for(i = 0, ttag = tag; ttag > 0; i++) ttag >>=7; |
209 | ttag = i; | 209 | ttag = i; |
210 | while(i-- > 0) | 210 | while(i-- > 0) |
211 | { | 211 | { |
212 | p[i] = tag & 0x7f; | 212 | p[i] = tag & 0x7f; |
213 | if(i != (ttag - 1)) p[i] |= 0x80; | 213 | if(i != (ttag - 1)) p[i] |= 0x80; |
214 | tag >>= 7; | 214 | tag >>= 7; |
215 | } | ||
216 | p += ttag; | ||
217 | } | 215 | } |
216 | p += ttag; | ||
217 | } | ||
218 | if (constructed == 2) | 218 | if (constructed == 2) |
219 | *(p++)=0x80; | 219 | *(p++)=0x80; |
220 | else | 220 | else |
221 | asn1_put_length(&p,length); | 221 | asn1_put_length(&p,length); |
222 | *pp=p; | 222 | *pp=p; |
223 | } | 223 | } |
224 | 224 | ||
225 | int ASN1_put_eoc(unsigned char **pp) | 225 | int ASN1_put_eoc(unsigned char **pp) |
226 | { | 226 | { |
227 | unsigned char *p = *pp; | 227 | unsigned char *p = *pp; |
228 | *p++ = 0; | 228 | *p++ = 0; |
229 | *p++ = 0; | 229 | *p++ = 0; |
230 | *pp = p; | 230 | *pp = p; |
231 | return 2; | 231 | return 2; |
232 | } | 232 | } |
233 | 233 | ||
234 | static void asn1_put_length(unsigned char **pp, int length) | 234 | static void asn1_put_length(unsigned char **pp, int length) |
235 | { | 235 | { |
236 | unsigned char *p= *pp; | 236 | unsigned char *p= *pp; |
237 | int i,l; | 237 | int i,l; |
238 | if (length <= 127) | 238 | if (length <= 127) |
239 | *(p++)=(unsigned char)length; | 239 | *(p++)=(unsigned char)length; |
240 | else | 240 | else |
241 | { | 241 | { |
242 | l=length; | 242 | l=length; |
243 | for (i=0; l > 0; i++) | 243 | for (i=0; l > 0; i++) |
244 | l>>=8; | 244 | l>>=8; |
245 | *(p++)=i|0x80; | 245 | *(p++)=i|0x80; |
246 | l=i; | 246 | l=i; |
247 | while (i-- > 0) | 247 | while (i-- > 0) |
248 | { | 248 | { |
249 | p[i]=length&0xff; | 249 | p[i]=length&0xff; |
250 | length>>=8; | 250 | length>>=8; |
251 | } | ||
252 | p+=l; | ||
253 | } | 251 | } |
254 | *pp=p; | 252 | p+=l; |
255 | } | 253 | } |
254 | *pp=p; | ||
255 | } | ||
256 | 256 | ||
257 | int ASN1_object_size(int constructed, int length, int tag) | 257 | int ASN1_object_size(int constructed, int length, int tag) |
258 | { | 258 | { |
259 | int ret; | 259 | int ret; |
260 | 260 | ||
261 | ret=length; | 261 | ret=length; |
262 | ret++; | 262 | ret++; |
263 | if (tag >= 31) | 263 | if (tag >= 31) |
264 | { | 264 | { |
265 | while (tag > 0) | 265 | while (tag > 0) |
266 | { | 266 | { |
267 | tag>>=7; | 267 | tag>>=7; |
268 | ret++; | 268 | ret++; |
269 | } | ||
270 | } | 269 | } |
270 | } | ||
271 | if (constructed == 2) | 271 | if (constructed == 2) |
272 | return ret + 3; | 272 | return ret + 3; |
273 | ret++; | 273 | ret++; |
274 | if (length > 127) | 274 | if (length > 127) |
275 | { | 275 | { |
276 | while (length > 0) | 276 | while (length > 0) |
277 | { | 277 | { |
278 | length>>=8; | 278 | length>>=8; |
279 | ret++; | 279 | ret++; |
280 | } | ||
281 | } | 280 | } |
282 | return(ret); | ||
283 | } | 281 | } |
282 | return(ret); | ||
283 | } | ||
284 | 284 | ||
285 | static int _asn1_Finish(ASN1_const_CTX *c) | 285 | static int _asn1_Finish(ASN1_const_CTX *c) |
286 | { | 286 | { |
287 | if ((c->inf == (1|V_ASN1_CONSTRUCTED)) && (!c->eos)) | 287 | if ((c->inf == (1|V_ASN1_CONSTRUCTED)) && (!c->eos)) |
288 | { | 288 | { |
289 | if (!ASN1_const_check_infinite_end(&c->p,c->slen)) | 289 | if (!ASN1_const_check_infinite_end(&c->p,c->slen)) |
290 | { | 290 | { |
291 | c->error=ERR_R_MISSING_ASN1_EOS; | 291 | c->error=ERR_R_MISSING_ASN1_EOS; |
292 | return(0); | 292 | return(0); |
293 | } | ||
294 | } | 293 | } |
294 | } | ||
295 | if ( ((c->slen != 0) && !(c->inf & 1)) || | 295 | if ( ((c->slen != 0) && !(c->inf & 1)) || |
296 | ((c->slen < 0) && (c->inf & 1))) | 296 | ((c->slen < 0) && (c->inf & 1))) |
297 | { | 297 | { |
298 | c->error=ERR_R_ASN1_LENGTH_MISMATCH; | 298 | c->error=ERR_R_ASN1_LENGTH_MISMATCH; |
299 | return(0); | 299 | return(0); |
300 | } | ||
301 | return(1); | ||
302 | } | 300 | } |
301 | return(1); | ||
302 | } | ||
303 | 303 | ||
304 | int asn1_Finish(ASN1_CTX *c) | 304 | int asn1_Finish(ASN1_CTX *c) |
305 | { | 305 | { |
306 | return _asn1_Finish((ASN1_const_CTX *)c); | 306 | return _asn1_Finish((ASN1_const_CTX *)c); |
307 | } | 307 | } |
308 | 308 | ||
309 | int asn1_const_Finish(ASN1_const_CTX *c) | 309 | int asn1_const_Finish(ASN1_const_CTX *c) |
310 | { | 310 | { |
311 | return _asn1_Finish(c); | 311 | return _asn1_Finish(c); |
312 | } | 312 | } |
313 | 313 | ||
314 | int asn1_GetSequence(ASN1_const_CTX *c, long *length) | 314 | int asn1_GetSequence(ASN1_const_CTX *c, long *length) |
315 | { | 315 | { |
316 | const unsigned char *q; | 316 | const unsigned char *q; |
317 | 317 | ||
318 | q=c->p; | 318 | q=c->p; |
319 | c->inf=ASN1_get_object(&(c->p),&(c->slen),&(c->tag),&(c->xclass), | 319 | c->inf=ASN1_get_object(&(c->p),&(c->slen),&(c->tag),&(c->xclass), |
320 | *length); | 320 | *length); |
321 | if (c->inf & 0x80) | 321 | if (c->inf & 0x80) |
322 | { | 322 | { |
323 | c->error=ERR_R_BAD_GET_ASN1_OBJECT_CALL; | 323 | c->error=ERR_R_BAD_GET_ASN1_OBJECT_CALL; |
324 | return(0); | 324 | return(0); |
325 | } | 325 | } |
326 | if (c->tag != V_ASN1_SEQUENCE) | 326 | if (c->tag != V_ASN1_SEQUENCE) |
327 | { | 327 | { |
328 | c->error=ERR_R_EXPECTING_AN_ASN1_SEQUENCE; | 328 | c->error=ERR_R_EXPECTING_AN_ASN1_SEQUENCE; |
329 | return(0); | 329 | return(0); |
330 | } | 330 | } |
331 | (*length)-=(c->p-q); | 331 | (*length)-=(c->p-q); |
332 | if (c->max && (*length < 0)) | 332 | if (c->max && (*length < 0)) |
333 | { | 333 | { |
334 | c->error=ERR_R_ASN1_LENGTH_MISMATCH; | 334 | c->error=ERR_R_ASN1_LENGTH_MISMATCH; |
335 | return(0); | 335 | return(0); |
336 | } | 336 | } |
337 | if (c->inf == (1|V_ASN1_CONSTRUCTED)) | 337 | if (c->inf == (1|V_ASN1_CONSTRUCTED)) |
338 | c->slen= *length+ *(c->pp)-c->p; | 338 | c->slen= *length+ *(c->pp)-c->p; |
339 | c->eos=0; | 339 | c->eos=0; |
340 | return(1); | 340 | return(1); |
341 | } | 341 | } |
342 | 342 | ||
343 | int ASN1_STRING_copy(ASN1_STRING *dst, const ASN1_STRING *str) | 343 | int ASN1_STRING_copy(ASN1_STRING *dst, const ASN1_STRING *str) |
344 | { | 344 | { |
345 | if (str == NULL) | 345 | if (str == NULL) |
346 | return 0; | 346 | return 0; |
347 | dst->type = str->type; | 347 | dst->type = str->type; |
@@ -349,10 +349,10 @@ int ASN1_STRING_copy(ASN1_STRING *dst, const ASN1_STRING *str) | |||
349 | return 0; | 349 | return 0; |
350 | dst->flags = str->flags; | 350 | dst->flags = str->flags; |
351 | return 1; | 351 | return 1; |
352 | } | 352 | } |
353 | 353 | ||
354 | ASN1_STRING *ASN1_STRING_dup(const ASN1_STRING *str) | 354 | ASN1_STRING *ASN1_STRING_dup(const ASN1_STRING *str) |
355 | { | 355 | { |
356 | ASN1_STRING *ret; | 356 | ASN1_STRING *ret; |
357 | if (!str) | 357 | if (!str) |
358 | return NULL; | 358 | return NULL; |
@@ -360,27 +360,27 @@ ASN1_STRING *ASN1_STRING_dup(const ASN1_STRING *str) | |||
360 | if (!ret) | 360 | if (!ret) |
361 | return NULL; | 361 | return NULL; |
362 | if (!ASN1_STRING_copy(ret,str)) | 362 | if (!ASN1_STRING_copy(ret,str)) |
363 | { | 363 | { |
364 | ASN1_STRING_free(ret); | 364 | ASN1_STRING_free(ret); |
365 | return NULL; | 365 | return NULL; |
366 | } | ||
367 | return ret; | ||
368 | } | 366 | } |
367 | return ret; | ||
368 | } | ||
369 | 369 | ||
370 | int ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len) | 370 | int ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len) |
371 | { | 371 | { |
372 | unsigned char *c; | 372 | unsigned char *c; |
373 | const char *data=_data; | 373 | const char *data=_data; |
374 | 374 | ||
375 | if (len < 0) | 375 | if (len < 0) |
376 | { | 376 | { |
377 | if (data == NULL) | 377 | if (data == NULL) |
378 | return(0); | 378 | return(0); |
379 | else | 379 | else |
380 | len=strlen(data); | 380 | len=strlen(data); |
381 | } | 381 | } |
382 | if ((str->length < len) || (str->data == NULL)) | 382 | if ((str->length < len) || (str->data == NULL)) |
383 | { | 383 | { |
384 | c=str->data; | 384 | c=str->data; |
385 | if (c == NULL) | 385 | if (c == NULL) |
386 | str->data=malloc(len+1); | 386 | str->data=malloc(len+1); |
@@ -388,86 +388,86 @@ int ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len) | |||
388 | str->data=realloc(c,len+1); | 388 | str->data=realloc(c,len+1); |
389 | 389 | ||
390 | if (str->data == NULL) | 390 | if (str->data == NULL) |
391 | { | 391 | { |
392 | ASN1err(ASN1_F_ASN1_STRING_SET,ERR_R_MALLOC_FAILURE); | 392 | ASN1err(ASN1_F_ASN1_STRING_SET,ERR_R_MALLOC_FAILURE); |
393 | str->data=c; | 393 | str->data=c; |
394 | return(0); | 394 | return(0); |
395 | } | ||
396 | } | 395 | } |
396 | } | ||
397 | str->length=len; | 397 | str->length=len; |
398 | if (data != NULL) | 398 | if (data != NULL) |
399 | { | 399 | { |
400 | memcpy(str->data,data,len); | 400 | memcpy(str->data,data,len); |
401 | /* an allowance for strings :-) */ | 401 | /* an allowance for strings :-) */ |
402 | str->data[len]='\0'; | 402 | str->data[len]='\0'; |
403 | } | ||
404 | return(1); | ||
405 | } | 403 | } |
404 | return(1); | ||
405 | } | ||
406 | 406 | ||
407 | void ASN1_STRING_set0(ASN1_STRING *str, void *data, int len) | 407 | void ASN1_STRING_set0(ASN1_STRING *str, void *data, int len) |
408 | { | 408 | { |
409 | if (str->data) | 409 | if (str->data) |
410 | free(str->data); | 410 | free(str->data); |
411 | str->data = data; | 411 | str->data = data; |
412 | str->length = len; | 412 | str->length = len; |
413 | } | 413 | } |
414 | 414 | ||
415 | ASN1_STRING *ASN1_STRING_new(void) | 415 | ASN1_STRING *ASN1_STRING_new(void) |
416 | { | 416 | { |
417 | return(ASN1_STRING_type_new(V_ASN1_OCTET_STRING)); | 417 | return(ASN1_STRING_type_new(V_ASN1_OCTET_STRING)); |
418 | } | 418 | } |
419 | 419 | ||
420 | 420 | ||
421 | ASN1_STRING *ASN1_STRING_type_new(int type) | 421 | ASN1_STRING *ASN1_STRING_type_new(int type) |
422 | { | 422 | { |
423 | ASN1_STRING *ret; | 423 | ASN1_STRING *ret; |
424 | 424 | ||
425 | ret=(ASN1_STRING *)malloc(sizeof(ASN1_STRING)); | 425 | ret=(ASN1_STRING *)malloc(sizeof(ASN1_STRING)); |
426 | if (ret == NULL) | 426 | if (ret == NULL) |
427 | { | 427 | { |
428 | ASN1err(ASN1_F_ASN1_STRING_TYPE_NEW,ERR_R_MALLOC_FAILURE); | 428 | ASN1err(ASN1_F_ASN1_STRING_TYPE_NEW,ERR_R_MALLOC_FAILURE); |
429 | return(NULL); | 429 | return(NULL); |
430 | } | 430 | } |
431 | ret->length=0; | 431 | ret->length=0; |
432 | ret->type=type; | 432 | ret->type=type; |
433 | ret->data=NULL; | 433 | ret->data=NULL; |
434 | ret->flags=0; | 434 | ret->flags=0; |
435 | return(ret); | 435 | return(ret); |
436 | } | 436 | } |
437 | 437 | ||
438 | void ASN1_STRING_free(ASN1_STRING *a) | 438 | void ASN1_STRING_free(ASN1_STRING *a) |
439 | { | 439 | { |
440 | if (a == NULL) return; | 440 | if (a == NULL) return; |
441 | if (a->data && !(a->flags & ASN1_STRING_FLAG_NDEF)) | 441 | if (a->data && !(a->flags & ASN1_STRING_FLAG_NDEF)) |
442 | free(a->data); | 442 | free(a->data); |
443 | free(a); | 443 | free(a); |
444 | } | 444 | } |
445 | 445 | ||
446 | int ASN1_STRING_cmp(const ASN1_STRING *a, const ASN1_STRING *b) | 446 | int ASN1_STRING_cmp(const ASN1_STRING *a, const ASN1_STRING *b) |
447 | { | 447 | { |
448 | int i; | 448 | int i; |
449 | 449 | ||
450 | i=(a->length-b->length); | 450 | i=(a->length-b->length); |
451 | if (i == 0) | 451 | if (i == 0) |
452 | { | 452 | { |
453 | i=memcmp(a->data,b->data,a->length); | 453 | i=memcmp(a->data,b->data,a->length); |
454 | if (i == 0) | 454 | if (i == 0) |
455 | return(a->type-b->type); | 455 | return(a->type-b->type); |
456 | else | 456 | else |
457 | return(i); | 457 | return(i); |
458 | } | 458 | } |
459 | else | 459 | else |
460 | return(i); | 460 | return(i); |
461 | } | 461 | } |
462 | 462 | ||
463 | void asn1_add_error(const unsigned char *address, int offset) | 463 | void asn1_add_error(const unsigned char *address, int offset) |
464 | { | 464 | { |
465 | char buf1[DECIMAL_SIZE(address)+1],buf2[DECIMAL_SIZE(offset)+1]; | 465 | char buf1[DECIMAL_SIZE(address)+1],buf2[DECIMAL_SIZE(offset)+1]; |
466 | 466 | ||
467 | (void) snprintf(buf1,sizeof buf1,"%lu",(unsigned long)address); | 467 | (void) snprintf(buf1,sizeof buf1,"%lu",(unsigned long)address); |
468 | (void) snprintf(buf2,sizeof buf2,"%d",offset); | 468 | (void) snprintf(buf2,sizeof buf2,"%d",offset); |
469 | ERR_add_error_data(4,"address=",buf1," offset=",buf2); | 469 | ERR_add_error_data(4,"address=",buf1," offset=",buf2); |
470 | } | 470 | } |
471 | 471 | ||
472 | int ASN1_STRING_length(const ASN1_STRING *x) | 472 | int ASN1_STRING_length(const ASN1_STRING *x) |
473 | { return M_ASN1_STRING_length(x); } | 473 | { return M_ASN1_STRING_length(x); } |
diff --git a/src/lib/libssl/src/crypto/asn1/asn1_par.c b/src/lib/libssl/src/crypto/asn1/asn1_par.c index e34c75a418..d68d4a8298 100644 --- a/src/lib/libssl/src/crypto/asn1/asn1_par.c +++ b/src/lib/libssl/src/crypto/asn1/asn1_par.c | |||
@@ -68,7 +68,7 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, | |||
68 | int offset, int depth, int indent, int dump); | 68 | int offset, int depth, int indent, int dump); |
69 | static int asn1_print_info(BIO *bp, int tag, int xclass, int constructed, | 69 | static int asn1_print_info(BIO *bp, int tag, int xclass, int constructed, |
70 | int indent) | 70 | int indent) |
71 | { | 71 | { |
72 | static const char fmt[]="%-18s"; | 72 | static const char fmt[]="%-18s"; |
73 | char str[128]; | 73 | char str[128]; |
74 | const char *p; | 74 | const char *p; |
@@ -97,21 +97,21 @@ static int asn1_print_info(BIO *bp, int tag, int xclass, int constructed, | |||
97 | return(1); | 97 | return(1); |
98 | err: | 98 | err: |
99 | return(0); | 99 | return(0); |
100 | } | 100 | } |
101 | 101 | ||
102 | int ASN1_parse(BIO *bp, const unsigned char *pp, long len, int indent) | 102 | int ASN1_parse(BIO *bp, const unsigned char *pp, long len, int indent) |
103 | { | 103 | { |
104 | return(asn1_parse2(bp,&pp,len,0,0,indent,0)); | 104 | return(asn1_parse2(bp,&pp,len,0,0,indent,0)); |
105 | } | 105 | } |
106 | 106 | ||
107 | int ASN1_parse_dump(BIO *bp, const unsigned char *pp, long len, int indent, int dump) | 107 | int ASN1_parse_dump(BIO *bp, const unsigned char *pp, long len, int indent, int dump) |
108 | { | 108 | { |
109 | return(asn1_parse2(bp,&pp,len,0,0,indent,dump)); | 109 | return(asn1_parse2(bp,&pp,len,0,0,indent,dump)); |
110 | } | 110 | } |
111 | 111 | ||
112 | static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offset, | 112 | static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offset, |
113 | int depth, int indent, int dump) | 113 | int depth, int indent, int dump) |
114 | { | 114 | { |
115 | const unsigned char *p,*ep,*tot,*op,*opp; | 115 | const unsigned char *p,*ep,*tot,*op,*opp; |
116 | long len; | 116 | long len; |
117 | int tag,xclass,ret=0; | 117 | int tag,xclass,ret=0; |
@@ -130,19 +130,19 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offse | |||
130 | tot=p+length; | 130 | tot=p+length; |
131 | op=p-1; | 131 | op=p-1; |
132 | while ((p < tot) && (op < p)) | 132 | while ((p < tot) && (op < p)) |
133 | { | 133 | { |
134 | op=p; | 134 | op=p; |
135 | j=ASN1_get_object(&p,&len,&tag,&xclass,length); | 135 | j=ASN1_get_object(&p,&len,&tag,&xclass,length); |
136 | #ifdef LINT | 136 | #ifdef LINT |
137 | j=j; | 137 | j=j; |
138 | #endif | 138 | #endif |
139 | if (j & 0x80) | 139 | if (j & 0x80) |
140 | { | 140 | { |
141 | if (BIO_write(bp,"Error in encoding\n",18) <= 0) | 141 | if (BIO_write(bp,"Error in encoding\n",18) <= 0) |
142 | goto end; | 142 | goto end; |
143 | ret=0; | 143 | ret=0; |
144 | goto end; | 144 | goto end; |
145 | } | 145 | } |
146 | hl=(p-op); | 146 | hl=(p-op); |
147 | length-=hl; | 147 | length-=hl; |
148 | /* if j == 0x21 it is a constructed indefinite length object */ | 148 | /* if j == 0x21 it is a constructed indefinite length object */ |
@@ -150,57 +150,57 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offse | |||
150 | <= 0) goto end; | 150 | <= 0) goto end; |
151 | 151 | ||
152 | if (j != (V_ASN1_CONSTRUCTED | 1)) | 152 | if (j != (V_ASN1_CONSTRUCTED | 1)) |
153 | { | 153 | { |
154 | if (BIO_printf(bp,"d=%-2d hl=%ld l=%4ld ", | 154 | if (BIO_printf(bp,"d=%-2d hl=%ld l=%4ld ", |
155 | depth,(long)hl,len) <= 0) | 155 | depth,(long)hl,len) <= 0) |
156 | goto end; | 156 | goto end; |
157 | } | 157 | } |
158 | else | 158 | else |
159 | { | 159 | { |
160 | if (BIO_printf(bp,"d=%-2d hl=%ld l=inf ", | 160 | if (BIO_printf(bp,"d=%-2d hl=%ld l=inf ", |
161 | depth,(long)hl) <= 0) | 161 | depth,(long)hl) <= 0) |
162 | goto end; | 162 | goto end; |
163 | } | 163 | } |
164 | if (!asn1_print_info(bp,tag,xclass,j,(indent)?depth:0)) | 164 | if (!asn1_print_info(bp,tag,xclass,j,(indent)?depth:0)) |
165 | goto end; | 165 | goto end; |
166 | if (j & V_ASN1_CONSTRUCTED) | 166 | if (j & V_ASN1_CONSTRUCTED) |
167 | { | 167 | { |
168 | ep=p+len; | 168 | ep=p+len; |
169 | if (BIO_write(bp,"\n",1) <= 0) goto end; | 169 | if (BIO_write(bp,"\n",1) <= 0) goto end; |
170 | if (len > length) | 170 | if (len > length) |
171 | { | 171 | { |
172 | BIO_printf(bp, | 172 | BIO_printf(bp, |
173 | "length is greater than %ld\n",length); | 173 | "length is greater than %ld\n",length); |
174 | ret=0; | 174 | ret=0; |
175 | goto end; | 175 | goto end; |
176 | } | 176 | } |
177 | if ((j == 0x21) && (len == 0)) | 177 | if ((j == 0x21) && (len == 0)) |
178 | { | 178 | { |
179 | for (;;) | 179 | for (;;) |
180 | { | 180 | { |
181 | r=asn1_parse2(bp,&p,(long)(tot-p), | 181 | r=asn1_parse2(bp,&p,(long)(tot-p), |
182 | offset+(p - *pp),depth+1, | 182 | offset+(p - *pp),depth+1, |
183 | indent,dump); | 183 | indent,dump); |
184 | if (r == 0) { ret=0; goto end; } | 184 | if (r == 0) { ret=0; goto end; } |
185 | if ((r == 2) || (p >= tot)) break; | 185 | if ((r == 2) || (p >= tot)) break; |
186 | } | ||
187 | } | 186 | } |
187 | } | ||
188 | else | 188 | else |
189 | while (p < ep) | 189 | while (p < ep) |
190 | { | 190 | { |
191 | r=asn1_parse2(bp,&p,(long)len, | 191 | r=asn1_parse2(bp,&p,(long)len, |
192 | offset+(p - *pp),depth+1, | 192 | offset+(p - *pp),depth+1, |
193 | indent,dump); | 193 | indent,dump); |
194 | if (r == 0) { ret=0; goto end; } | 194 | if (r == 0) { ret=0; goto end; } |
195 | } | 195 | } |
196 | } | 196 | } |
197 | else if (xclass != 0) | 197 | else if (xclass != 0) |
198 | { | 198 | { |
199 | p+=len; | 199 | p+=len; |
200 | if (BIO_write(bp,"\n",1) <= 0) goto end; | 200 | if (BIO_write(bp,"\n",1) <= 0) goto end; |
201 | } | 201 | } |
202 | else | 202 | else |
203 | { | 203 | { |
204 | nl=0; | 204 | nl=0; |
205 | if ( (tag == V_ASN1_PRINTABLESTRING) || | 205 | if ( (tag == V_ASN1_PRINTABLESTRING) || |
206 | (tag == V_ASN1_T61STRING) || | 206 | (tag == V_ASN1_T61STRING) || |
@@ -210,97 +210,97 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offse | |||
210 | (tag == V_ASN1_UTF8STRING) || | 210 | (tag == V_ASN1_UTF8STRING) || |
211 | (tag == V_ASN1_UTCTIME) || | 211 | (tag == V_ASN1_UTCTIME) || |
212 | (tag == V_ASN1_GENERALIZEDTIME)) | 212 | (tag == V_ASN1_GENERALIZEDTIME)) |
213 | { | 213 | { |
214 | if (BIO_write(bp,":",1) <= 0) goto end; | 214 | if (BIO_write(bp,":",1) <= 0) goto end; |
215 | if ((len > 0) && | 215 | if ((len > 0) && |
216 | BIO_write(bp,(const char *)p,(int)len) | 216 | BIO_write(bp,(const char *)p,(int)len) |
217 | != (int)len) | 217 | != (int)len) |
218 | goto end; | 218 | goto end; |
219 | } | 219 | } |
220 | else if (tag == V_ASN1_OBJECT) | 220 | else if (tag == V_ASN1_OBJECT) |
221 | { | 221 | { |
222 | opp=op; | 222 | opp=op; |
223 | if (d2i_ASN1_OBJECT(&o,&opp,len+hl) != NULL) | 223 | if (d2i_ASN1_OBJECT(&o,&opp,len+hl) != NULL) |
224 | { | 224 | { |
225 | if (BIO_write(bp,":",1) <= 0) goto end; | 225 | if (BIO_write(bp,":",1) <= 0) goto end; |
226 | i2a_ASN1_OBJECT(bp,o); | 226 | i2a_ASN1_OBJECT(bp,o); |
227 | } | 227 | } |
228 | else | 228 | else |
229 | { | 229 | { |
230 | if (BIO_write(bp,":BAD OBJECT",11) <= 0) | 230 | if (BIO_write(bp,":BAD OBJECT",11) <= 0) |
231 | goto end; | 231 | goto end; |
232 | } | ||
233 | } | 232 | } |
233 | } | ||
234 | else if (tag == V_ASN1_BOOLEAN) | 234 | else if (tag == V_ASN1_BOOLEAN) |
235 | { | 235 | { |
236 | int ii; | 236 | int ii; |
237 | 237 | ||
238 | opp=op; | 238 | opp=op; |
239 | ii=d2i_ASN1_BOOLEAN(NULL,&opp,len+hl); | 239 | ii=d2i_ASN1_BOOLEAN(NULL,&opp,len+hl); |
240 | if (ii < 0) | 240 | if (ii < 0) |
241 | { | 241 | { |
242 | if (BIO_write(bp,"Bad boolean\n",12) <= 0) | 242 | if (BIO_write(bp,"Bad boolean\n",12) <= 0) |
243 | goto end; | 243 | goto end; |
244 | } | ||
245 | BIO_printf(bp,":%d",ii); | ||
246 | } | 244 | } |
245 | BIO_printf(bp,":%d",ii); | ||
246 | } | ||
247 | else if (tag == V_ASN1_BMPSTRING) | 247 | else if (tag == V_ASN1_BMPSTRING) |
248 | { | 248 | { |
249 | /* do the BMP thang */ | 249 | /* do the BMP thang */ |
250 | } | 250 | } |
251 | else if (tag == V_ASN1_OCTET_STRING) | 251 | else if (tag == V_ASN1_OCTET_STRING) |
252 | { | 252 | { |
253 | int i,printable=1; | 253 | int i,printable=1; |
254 | 254 | ||
255 | opp=op; | 255 | opp=op; |
256 | os=d2i_ASN1_OCTET_STRING(NULL,&opp,len+hl); | 256 | os=d2i_ASN1_OCTET_STRING(NULL,&opp,len+hl); |
257 | if (os != NULL && os->length > 0) | 257 | if (os != NULL && os->length > 0) |
258 | { | 258 | { |
259 | opp = os->data; | 259 | opp = os->data; |
260 | /* testing whether the octet string is | 260 | /* testing whether the octet string is |
261 | * printable */ | 261 | * printable */ |
262 | for (i=0; i<os->length; i++) | 262 | for (i=0; i<os->length; i++) |
263 | { | 263 | { |
264 | if (( (opp[i] < ' ') && | 264 | if (( (opp[i] < ' ') && |
265 | (opp[i] != '\n') && | 265 | (opp[i] != '\n') && |
266 | (opp[i] != '\r') && | 266 | (opp[i] != '\r') && |
267 | (opp[i] != '\t')) || | 267 | (opp[i] != '\t')) || |
268 | (opp[i] > '~')) | 268 | (opp[i] > '~')) |
269 | { | 269 | { |
270 | printable=0; | 270 | printable=0; |
271 | break; | 271 | break; |
272 | } | ||
273 | } | 272 | } |
273 | } | ||
274 | if (printable) | 274 | if (printable) |
275 | /* printable string */ | 275 | /* printable string */ |
276 | { | 276 | { |
277 | if (BIO_write(bp,":",1) <= 0) | 277 | if (BIO_write(bp,":",1) <= 0) |
278 | goto end; | 278 | goto end; |
279 | if (BIO_write(bp,(const char *)opp, | 279 | if (BIO_write(bp,(const char *)opp, |
280 | os->length) <= 0) | 280 | os->length) <= 0) |
281 | goto end; | 281 | goto end; |
282 | } | 282 | } |
283 | else if (!dump) | 283 | else if (!dump) |
284 | /* not printable => print octet string | 284 | /* not printable => print octet string |
285 | * as hex dump */ | 285 | * as hex dump */ |
286 | { | 286 | { |
287 | if (BIO_write(bp,"[HEX DUMP]:",11) <= 0) | 287 | if (BIO_write(bp,"[HEX DUMP]:",11) <= 0) |
288 | goto end; | 288 | goto end; |
289 | for (i=0; i<os->length; i++) | 289 | for (i=0; i<os->length; i++) |
290 | { | 290 | { |
291 | if (BIO_printf(bp,"%02X" | 291 | if (BIO_printf(bp,"%02X" |
292 | , opp[i]) <= 0) | 292 | , opp[i]) <= 0) |
293 | goto end; | 293 | goto end; |
294 | } | ||
295 | } | 294 | } |
295 | } | ||
296 | else | 296 | else |
297 | /* print the normal dump */ | 297 | /* print the normal dump */ |
298 | { | 298 | { |
299 | if (!nl) | 299 | if (!nl) |
300 | { | 300 | { |
301 | if (BIO_write(bp,"\n",1) <= 0) | 301 | if (BIO_write(bp,"\n",1) <= 0) |
302 | goto end; | 302 | goto end; |
303 | } | 303 | } |
304 | if (BIO_dump_indent(bp, | 304 | if (BIO_dump_indent(bp, |
305 | (const char *)opp, | 305 | (const char *)opp, |
306 | ((dump == -1 || dump > | 306 | ((dump == -1 || dump > |
@@ -308,112 +308,112 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offse | |||
308 | dump_indent) <= 0) | 308 | dump_indent) <= 0) |
309 | goto end; | 309 | goto end; |
310 | nl=1; | 310 | nl=1; |
311 | } | ||
312 | } | 311 | } |
312 | } | ||
313 | if (os != NULL) | 313 | if (os != NULL) |
314 | { | 314 | { |
315 | M_ASN1_OCTET_STRING_free(os); | 315 | M_ASN1_OCTET_STRING_free(os); |
316 | os=NULL; | 316 | os=NULL; |
317 | } | ||
318 | } | 317 | } |
318 | } | ||
319 | else if (tag == V_ASN1_INTEGER) | 319 | else if (tag == V_ASN1_INTEGER) |
320 | { | 320 | { |
321 | ASN1_INTEGER *bs; | 321 | ASN1_INTEGER *bs; |
322 | int i; | 322 | int i; |
323 | 323 | ||
324 | opp=op; | 324 | opp=op; |
325 | bs=d2i_ASN1_INTEGER(NULL,&opp,len+hl); | 325 | bs=d2i_ASN1_INTEGER(NULL,&opp,len+hl); |
326 | if (bs != NULL) | 326 | if (bs != NULL) |
327 | { | 327 | { |
328 | if (BIO_write(bp,":",1) <= 0) goto end; | 328 | if (BIO_write(bp,":",1) <= 0) goto end; |
329 | if (bs->type == V_ASN1_NEG_INTEGER) | 329 | if (bs->type == V_ASN1_NEG_INTEGER) |
330 | if (BIO_write(bp,"-",1) <= 0) | 330 | if (BIO_write(bp,"-",1) <= 0) |
331 | goto end; | 331 | goto end; |
332 | for (i=0; i<bs->length; i++) | 332 | for (i=0; i<bs->length; i++) |
333 | { | 333 | { |
334 | if (BIO_printf(bp,"%02X", | 334 | if (BIO_printf(bp,"%02X", |
335 | bs->data[i]) <= 0) | 335 | bs->data[i]) <= 0) |
336 | goto end; | 336 | goto end; |
337 | } | 337 | } |
338 | if (bs->length == 0) | 338 | if (bs->length == 0) |
339 | { | 339 | { |
340 | if (BIO_write(bp,"00",2) <= 0) | 340 | if (BIO_write(bp,"00",2) <= 0) |
341 | goto end; | 341 | goto end; |
342 | } | ||
343 | } | 342 | } |
343 | } | ||
344 | else | 344 | else |
345 | { | 345 | { |
346 | if (BIO_write(bp,"BAD INTEGER",11) <= 0) | 346 | if (BIO_write(bp,"BAD INTEGER",11) <= 0) |
347 | goto end; | 347 | goto end; |
348 | } | ||
349 | M_ASN1_INTEGER_free(bs); | ||
350 | } | 348 | } |
349 | M_ASN1_INTEGER_free(bs); | ||
350 | } | ||
351 | else if (tag == V_ASN1_ENUMERATED) | 351 | else if (tag == V_ASN1_ENUMERATED) |
352 | { | 352 | { |
353 | ASN1_ENUMERATED *bs; | 353 | ASN1_ENUMERATED *bs; |
354 | int i; | 354 | int i; |
355 | 355 | ||
356 | opp=op; | 356 | opp=op; |
357 | bs=d2i_ASN1_ENUMERATED(NULL,&opp,len+hl); | 357 | bs=d2i_ASN1_ENUMERATED(NULL,&opp,len+hl); |
358 | if (bs != NULL) | 358 | if (bs != NULL) |
359 | { | 359 | { |
360 | if (BIO_write(bp,":",1) <= 0) goto end; | 360 | if (BIO_write(bp,":",1) <= 0) goto end; |
361 | if (bs->type == V_ASN1_NEG_ENUMERATED) | 361 | if (bs->type == V_ASN1_NEG_ENUMERATED) |
362 | if (BIO_write(bp,"-",1) <= 0) | 362 | if (BIO_write(bp,"-",1) <= 0) |
363 | goto end; | 363 | goto end; |
364 | for (i=0; i<bs->length; i++) | 364 | for (i=0; i<bs->length; i++) |
365 | { | 365 | { |
366 | if (BIO_printf(bp,"%02X", | 366 | if (BIO_printf(bp,"%02X", |
367 | bs->data[i]) <= 0) | 367 | bs->data[i]) <= 0) |
368 | goto end; | 368 | goto end; |
369 | } | 369 | } |
370 | if (bs->length == 0) | 370 | if (bs->length == 0) |
371 | { | 371 | { |
372 | if (BIO_write(bp,"00",2) <= 0) | 372 | if (BIO_write(bp,"00",2) <= 0) |
373 | goto end; | 373 | goto end; |
374 | } | ||
375 | } | 374 | } |
375 | } | ||
376 | else | 376 | else |
377 | { | 377 | { |
378 | if (BIO_write(bp,"BAD ENUMERATED",14) <= 0) | 378 | if (BIO_write(bp,"BAD ENUMERATED",14) <= 0) |
379 | goto end; | 379 | goto end; |
380 | } | ||
381 | M_ASN1_ENUMERATED_free(bs); | ||
382 | } | 380 | } |
381 | M_ASN1_ENUMERATED_free(bs); | ||
382 | } | ||
383 | else if (len > 0 && dump) | 383 | else if (len > 0 && dump) |
384 | { | 384 | { |
385 | if (!nl) | 385 | if (!nl) |
386 | { | 386 | { |
387 | if (BIO_write(bp,"\n",1) <= 0) | 387 | if (BIO_write(bp,"\n",1) <= 0) |
388 | goto end; | 388 | goto end; |
389 | } | 389 | } |
390 | if (BIO_dump_indent(bp,(const char *)p, | 390 | if (BIO_dump_indent(bp,(const char *)p, |
391 | ((dump == -1 || dump > len)?len:dump), | 391 | ((dump == -1 || dump > len)?len:dump), |
392 | dump_indent) <= 0) | 392 | dump_indent) <= 0) |
393 | goto end; | 393 | goto end; |
394 | nl=1; | 394 | nl=1; |
395 | } | 395 | } |
396 | 396 | ||
397 | if (!nl) | 397 | if (!nl) |
398 | { | 398 | { |
399 | if (BIO_write(bp,"\n",1) <= 0) goto end; | 399 | if (BIO_write(bp,"\n",1) <= 0) goto end; |
400 | } | 400 | } |
401 | p+=len; | 401 | p+=len; |
402 | if ((tag == V_ASN1_EOC) && (xclass == 0)) | 402 | if ((tag == V_ASN1_EOC) && (xclass == 0)) |
403 | { | 403 | { |
404 | ret=2; /* End of sequence */ | 404 | ret=2; /* End of sequence */ |
405 | goto end; | 405 | goto end; |
406 | } | ||
407 | } | 406 | } |
408 | length-=len; | ||
409 | } | 407 | } |
408 | length-=len; | ||
409 | } | ||
410 | ret=1; | 410 | ret=1; |
411 | end: | 411 | end: |
412 | if (o != NULL) ASN1_OBJECT_free(o); | 412 | if (o != NULL) ASN1_OBJECT_free(o); |
413 | if (os != NULL) M_ASN1_OCTET_STRING_free(os); | 413 | if (os != NULL) M_ASN1_OCTET_STRING_free(os); |
414 | *pp=p; | 414 | *pp=p; |
415 | return(ret); | 415 | return(ret); |
416 | } | 416 | } |
417 | 417 | ||
418 | const char *ASN1_tag2str(int tag) | 418 | const char *ASN1_tag2str(int tag) |
419 | { | 419 | { |
@@ -426,7 +426,7 @@ const char *ASN1_tag2str(int tag) | |||
426 | "VIDEOTEXSTRING", "IA5STRING", "UTCTIME","GENERALIZEDTIME", /* 21-24 */ | 426 | "VIDEOTEXSTRING", "IA5STRING", "UTCTIME","GENERALIZEDTIME", /* 21-24 */ |
427 | "GRAPHICSTRING", "VISIBLESTRING", "GENERALSTRING", /* 25-27 */ | 427 | "GRAPHICSTRING", "VISIBLESTRING", "GENERALSTRING", /* 25-27 */ |
428 | "UNIVERSALSTRING", "<ASN1 29>", "BMPSTRING" /* 28-30 */ | 428 | "UNIVERSALSTRING", "<ASN1 29>", "BMPSTRING" /* 28-30 */ |
429 | }; | 429 | }; |
430 | 430 | ||
431 | if((tag == V_ASN1_NEG_INTEGER) || (tag == V_ASN1_NEG_ENUMERATED)) | 431 | if((tag == V_ASN1_NEG_INTEGER) || (tag == V_ASN1_NEG_ENUMERATED)) |
432 | tag &= ~0x100; | 432 | tag &= ~0x100; |
diff --git a/src/lib/libssl/src/crypto/asn1/asn_mime.c b/src/lib/libssl/src/crypto/asn1/asn_mime.c index 2b600ab411..011b97ff92 100644 --- a/src/lib/libssl/src/crypto/asn1/asn_mime.c +++ b/src/lib/libssl/src/crypto/asn1/asn_mime.c | |||
@@ -114,48 +114,48 @@ static void mime_hdr_free(MIME_HEADER *hdr); | |||
114 | 114 | ||
115 | int i2d_ASN1_bio_stream(BIO *out, ASN1_VALUE *val, BIO *in, int flags, | 115 | int i2d_ASN1_bio_stream(BIO *out, ASN1_VALUE *val, BIO *in, int flags, |
116 | const ASN1_ITEM *it) | 116 | const ASN1_ITEM *it) |
117 | { | 117 | { |
118 | /* If streaming create stream BIO and copy all content through it */ | 118 | /* If streaming create stream BIO and copy all content through it */ |
119 | if (flags & SMIME_STREAM) | 119 | if (flags & SMIME_STREAM) |
120 | { | 120 | { |
121 | BIO *bio, *tbio; | 121 | BIO *bio, *tbio; |
122 | bio = BIO_new_NDEF(out, val, it); | 122 | bio = BIO_new_NDEF(out, val, it); |
123 | if (!bio) | 123 | if (!bio) |
124 | { | 124 | { |
125 | ASN1err(ASN1_F_I2D_ASN1_BIO_STREAM,ERR_R_MALLOC_FAILURE); | 125 | ASN1err(ASN1_F_I2D_ASN1_BIO_STREAM,ERR_R_MALLOC_FAILURE); |
126 | return 0; | 126 | return 0; |
127 | } | 127 | } |
128 | SMIME_crlf_copy(in, bio, flags); | 128 | SMIME_crlf_copy(in, bio, flags); |
129 | (void)BIO_flush(bio); | 129 | (void)BIO_flush(bio); |
130 | /* Free up successive BIOs until we hit the old output BIO */ | 130 | /* Free up successive BIOs until we hit the old output BIO */ |
131 | do | 131 | do |
132 | { | 132 | { |
133 | tbio = BIO_pop(bio); | 133 | tbio = BIO_pop(bio); |
134 | BIO_free(bio); | 134 | BIO_free(bio); |
135 | bio = tbio; | 135 | bio = tbio; |
136 | } while (bio != out); | 136 | } while (bio != out); |
137 | } | 137 | } |
138 | /* else just write out ASN1 structure which will have all content | 138 | /* else just write out ASN1 structure which will have all content |
139 | * stored internally | 139 | * stored internally |
140 | */ | 140 | */ |
141 | else | 141 | else |
142 | ASN1_item_i2d_bio(it, out, val); | 142 | ASN1_item_i2d_bio(it, out, val); |
143 | return 1; | 143 | return 1; |
144 | } | 144 | } |
145 | 145 | ||
146 | /* Base 64 read and write of ASN1 structure */ | 146 | /* Base 64 read and write of ASN1 structure */ |
147 | 147 | ||
148 | static int B64_write_ASN1(BIO *out, ASN1_VALUE *val, BIO *in, int flags, | 148 | static int B64_write_ASN1(BIO *out, ASN1_VALUE *val, BIO *in, int flags, |
149 | const ASN1_ITEM *it) | 149 | const ASN1_ITEM *it) |
150 | { | 150 | { |
151 | BIO *b64; | 151 | BIO *b64; |
152 | int r; | 152 | int r; |
153 | b64 = BIO_new(BIO_f_base64()); | 153 | b64 = BIO_new(BIO_f_base64()); |
154 | if(!b64) | 154 | if(!b64) |
155 | { | 155 | { |
156 | ASN1err(ASN1_F_B64_WRITE_ASN1,ERR_R_MALLOC_FAILURE); | 156 | ASN1err(ASN1_F_B64_WRITE_ASN1,ERR_R_MALLOC_FAILURE); |
157 | return 0; | 157 | return 0; |
158 | } | 158 | } |
159 | /* prepend the b64 BIO so all data is base64 encoded. | 159 | /* prepend the b64 BIO so all data is base64 encoded. |
160 | */ | 160 | */ |
161 | out = BIO_push(b64, out); | 161 | out = BIO_push(b64, out); |
@@ -164,20 +164,20 @@ static int B64_write_ASN1(BIO *out, ASN1_VALUE *val, BIO *in, int flags, | |||
164 | BIO_pop(out); | 164 | BIO_pop(out); |
165 | BIO_free(b64); | 165 | BIO_free(b64); |
166 | return r; | 166 | return r; |
167 | } | 167 | } |
168 | 168 | ||
169 | /* Streaming ASN1 PEM write */ | 169 | /* Streaming ASN1 PEM write */ |
170 | 170 | ||
171 | int PEM_write_bio_ASN1_stream(BIO *out, ASN1_VALUE *val, BIO *in, int flags, | 171 | int PEM_write_bio_ASN1_stream(BIO *out, ASN1_VALUE *val, BIO *in, int flags, |
172 | const char *hdr, | 172 | const char *hdr, |
173 | const ASN1_ITEM *it) | 173 | const ASN1_ITEM *it) |
174 | { | 174 | { |
175 | int r; | 175 | int r; |
176 | BIO_printf(out, "-----BEGIN %s-----\n", hdr); | 176 | BIO_printf(out, "-----BEGIN %s-----\n", hdr); |
177 | r = B64_write_ASN1(out, val, in, flags, it); | 177 | r = B64_write_ASN1(out, val, in, flags, it); |
178 | BIO_printf(out, "-----END %s-----\n", hdr); | 178 | BIO_printf(out, "-----END %s-----\n", hdr); |
179 | return r; | 179 | return r; |
180 | } | 180 | } |
181 | 181 | ||
182 | static ASN1_VALUE *b64_read_asn1(BIO *bio, const ASN1_ITEM *it) | 182 | static ASN1_VALUE *b64_read_asn1(BIO *bio, const ASN1_ITEM *it) |
183 | { | 183 | { |
@@ -186,7 +186,7 @@ static ASN1_VALUE *b64_read_asn1(BIO *bio, const ASN1_ITEM *it) | |||
186 | if(!(b64 = BIO_new(BIO_f_base64()))) { | 186 | if(!(b64 = BIO_new(BIO_f_base64()))) { |
187 | ASN1err(ASN1_F_B64_READ_ASN1,ERR_R_MALLOC_FAILURE); | 187 | ASN1err(ASN1_F_B64_READ_ASN1,ERR_R_MALLOC_FAILURE); |
188 | return 0; | 188 | return 0; |
189 | } | 189 | } |
190 | bio = BIO_push(b64, bio); | 190 | bio = BIO_push(b64, bio); |
191 | val = ASN1_item_d2i_bio(it, bio, NULL); | 191 | val = ASN1_item_d2i_bio(it, bio, NULL); |
192 | if(!val) | 192 | if(!val) |
@@ -200,34 +200,34 @@ static ASN1_VALUE *b64_read_asn1(BIO *bio, const ASN1_ITEM *it) | |||
200 | /* Generate the MIME "micalg" parameter from RFC3851, RFC4490 */ | 200 | /* Generate the MIME "micalg" parameter from RFC3851, RFC4490 */ |
201 | 201 | ||
202 | static int asn1_write_micalg(BIO *out, STACK_OF(X509_ALGOR) *mdalgs) | 202 | static int asn1_write_micalg(BIO *out, STACK_OF(X509_ALGOR) *mdalgs) |
203 | { | 203 | { |
204 | const EVP_MD *md; | 204 | const EVP_MD *md; |
205 | int i, have_unknown = 0, write_comma, ret = 0, md_nid; | 205 | int i, have_unknown = 0, write_comma, ret = 0, md_nid; |
206 | have_unknown = 0; | 206 | have_unknown = 0; |
207 | write_comma = 0; | 207 | write_comma = 0; |
208 | for (i = 0; i < sk_X509_ALGOR_num(mdalgs); i++) | 208 | for (i = 0; i < sk_X509_ALGOR_num(mdalgs); i++) |
209 | { | 209 | { |
210 | if (write_comma) | 210 | if (write_comma) |
211 | BIO_write(out, ",", 1); | 211 | BIO_write(out, ",", 1); |
212 | write_comma = 1; | 212 | write_comma = 1; |
213 | md_nid = OBJ_obj2nid(sk_X509_ALGOR_value(mdalgs, i)->algorithm); | 213 | md_nid = OBJ_obj2nid(sk_X509_ALGOR_value(mdalgs, i)->algorithm); |
214 | md = EVP_get_digestbynid(md_nid); | 214 | md = EVP_get_digestbynid(md_nid); |
215 | if (md && md->md_ctrl) | 215 | if (md && md->md_ctrl) |
216 | { | 216 | { |
217 | int rv; | 217 | int rv; |
218 | char *micstr; | 218 | char *micstr; |
219 | rv = md->md_ctrl(NULL, EVP_MD_CTRL_MICALG, 0, &micstr); | 219 | rv = md->md_ctrl(NULL, EVP_MD_CTRL_MICALG, 0, &micstr); |
220 | if (rv > 0) | 220 | if (rv > 0) |
221 | { | 221 | { |
222 | BIO_puts(out, micstr); | 222 | BIO_puts(out, micstr); |
223 | free(micstr); | 223 | free(micstr); |
224 | continue; | 224 | continue; |
225 | } | 225 | } |
226 | if (rv != -2) | 226 | if (rv != -2) |
227 | goto err; | 227 | goto err; |
228 | } | 228 | } |
229 | switch(md_nid) | 229 | switch(md_nid) |
230 | { | 230 | { |
231 | case NID_sha1: | 231 | case NID_sha1: |
232 | BIO_puts(out, "sha1"); | 232 | BIO_puts(out, "sha1"); |
233 | break; | 233 | break; |
@@ -257,21 +257,21 @@ static int asn1_write_micalg(BIO *out, STACK_OF(X509_ALGOR) *mdalgs) | |||
257 | if (have_unknown) | 257 | if (have_unknown) |
258 | write_comma = 0; | 258 | write_comma = 0; |
259 | else | 259 | else |
260 | { | 260 | { |
261 | BIO_puts(out, "unknown"); | 261 | BIO_puts(out, "unknown"); |
262 | have_unknown = 1; | 262 | have_unknown = 1; |
263 | } | 263 | } |
264 | break; | 264 | break; |
265 | 265 | ||
266 | } | ||
267 | } | 266 | } |
267 | } | ||
268 | 268 | ||
269 | ret = 1; | 269 | ret = 1; |
270 | err: | 270 | err: |
271 | 271 | ||
272 | return ret; | 272 | return ret; |
273 | 273 | ||
274 | } | 274 | } |
275 | 275 | ||
276 | /* SMIME sender */ | 276 | /* SMIME sender */ |
277 | 277 | ||
@@ -302,7 +302,7 @@ int SMIME_write_ASN1(BIO *bio, ASN1_VALUE *val, BIO *data, int flags, | |||
302 | if(c < 10) c += '0'; | 302 | if(c < 10) c += '0'; |
303 | else c += 'A' - 10; | 303 | else c += 'A' - 10; |
304 | bound[i] = c; | 304 | bound[i] = c; |
305 | } | 305 | } |
306 | bound[32] = 0; | 306 | bound[32] = 0; |
307 | BIO_printf(bio, "MIME-Version: 1.0%s", mime_eol); | 307 | BIO_printf(bio, "MIME-Version: 1.0%s", mime_eol); |
308 | BIO_printf(bio, "Content-Type: multipart/signed;"); | 308 | BIO_printf(bio, "Content-Type: multipart/signed;"); |
@@ -332,26 +332,26 @@ int SMIME_write_ASN1(BIO *bio, ASN1_VALUE *val, BIO *data, int flags, | |||
332 | BIO_printf(bio,"%s------%s--%s%s", mime_eol, bound, | 332 | BIO_printf(bio,"%s------%s--%s%s", mime_eol, bound, |
333 | mime_eol, mime_eol); | 333 | mime_eol, mime_eol); |
334 | return 1; | 334 | return 1; |
335 | } | 335 | } |
336 | 336 | ||
337 | /* Determine smime-type header */ | 337 | /* Determine smime-type header */ |
338 | 338 | ||
339 | if (ctype_nid == NID_pkcs7_enveloped) | 339 | if (ctype_nid == NID_pkcs7_enveloped) |
340 | msg_type = "enveloped-data"; | 340 | msg_type = "enveloped-data"; |
341 | else if (ctype_nid == NID_pkcs7_signed) | 341 | else if (ctype_nid == NID_pkcs7_signed) |
342 | { | 342 | { |
343 | if (econt_nid == NID_id_smime_ct_receipt) | 343 | if (econt_nid == NID_id_smime_ct_receipt) |
344 | msg_type = "signed-receipt"; | 344 | msg_type = "signed-receipt"; |
345 | else if (sk_X509_ALGOR_num(mdalgs) >= 0) | 345 | else if (sk_X509_ALGOR_num(mdalgs) >= 0) |
346 | msg_type = "signed-data"; | 346 | msg_type = "signed-data"; |
347 | else | 347 | else |
348 | msg_type = "certs-only"; | 348 | msg_type = "certs-only"; |
349 | } | 349 | } |
350 | else if (ctype_nid == NID_id_smime_ct_compressedData) | 350 | else if (ctype_nid == NID_id_smime_ct_compressedData) |
351 | { | 351 | { |
352 | msg_type = "compressed-data"; | 352 | msg_type = "compressed-data"; |
353 | cname = "smime.p7z"; | 353 | cname = "smime.p7z"; |
354 | } | 354 | } |
355 | /* MIME headers */ | 355 | /* MIME headers */ |
356 | BIO_printf(bio, "MIME-Version: 1.0%s", mime_eol); | 356 | BIO_printf(bio, "MIME-Version: 1.0%s", mime_eol); |
357 | BIO_printf(bio, "Content-Disposition: attachment;"); | 357 | BIO_printf(bio, "Content-Disposition: attachment;"); |
@@ -373,7 +373,7 @@ int SMIME_write_ASN1(BIO *bio, ASN1_VALUE *val, BIO *data, int flags, | |||
373 | 373 | ||
374 | static int asn1_output_data(BIO *out, BIO *data, ASN1_VALUE *val, int flags, | 374 | static int asn1_output_data(BIO *out, BIO *data, ASN1_VALUE *val, int flags, |
375 | const ASN1_ITEM *it) | 375 | const ASN1_ITEM *it) |
376 | { | 376 | { |
377 | BIO *tmpbio; | 377 | BIO *tmpbio; |
378 | const ASN1_AUX *aux = it->funcs; | 378 | const ASN1_AUX *aux = it->funcs; |
379 | ASN1_STREAM_ARG sarg; | 379 | ASN1_STREAM_ARG sarg; |
@@ -383,17 +383,17 @@ static int asn1_output_data(BIO *out, BIO *data, ASN1_VALUE *val, int flags, | |||
383 | * already set up to finalise when it is written through. | 383 | * already set up to finalise when it is written through. |
384 | */ | 384 | */ |
385 | if (!(flags & SMIME_DETACHED) || (flags & PKCS7_REUSE_DIGEST)) | 385 | if (!(flags & SMIME_DETACHED) || (flags & PKCS7_REUSE_DIGEST)) |
386 | { | 386 | { |
387 | SMIME_crlf_copy(data, out, flags); | 387 | SMIME_crlf_copy(data, out, flags); |
388 | return 1; | 388 | return 1; |
389 | } | 389 | } |
390 | 390 | ||
391 | if (!aux || !aux->asn1_cb) | 391 | if (!aux || !aux->asn1_cb) |
392 | { | 392 | { |
393 | ASN1err(ASN1_F_ASN1_OUTPUT_DATA, | 393 | ASN1err(ASN1_F_ASN1_OUTPUT_DATA, |
394 | ASN1_R_STREAMING_NOT_SUPPORTED); | 394 | ASN1_R_STREAMING_NOT_SUPPORTED); |
395 | return 0; | 395 | return 0; |
396 | } | 396 | } |
397 | 397 | ||
398 | sarg.out = out; | 398 | sarg.out = out; |
399 | sarg.ndef_bio = NULL; | 399 | sarg.ndef_bio = NULL; |
@@ -414,15 +414,15 @@ static int asn1_output_data(BIO *out, BIO *data, ASN1_VALUE *val, int flags, | |||
414 | /* Now remove any digests prepended to the BIO */ | 414 | /* Now remove any digests prepended to the BIO */ |
415 | 415 | ||
416 | while (sarg.ndef_bio != out) | 416 | while (sarg.ndef_bio != out) |
417 | { | 417 | { |
418 | tmpbio = BIO_pop(sarg.ndef_bio); | 418 | tmpbio = BIO_pop(sarg.ndef_bio); |
419 | BIO_free(sarg.ndef_bio); | 419 | BIO_free(sarg.ndef_bio); |
420 | sarg.ndef_bio = tmpbio; | 420 | sarg.ndef_bio = tmpbio; |
421 | } | 421 | } |
422 | 422 | ||
423 | return rv; | 423 | return rv; |
424 | 424 | ||
425 | } | 425 | } |
426 | 426 | ||
427 | /* SMIME reader: handle multipart/signed and opaque signing. | 427 | /* SMIME reader: handle multipart/signed and opaque signing. |
428 | * in multipart case the content is placed in a memory BIO | 428 | * in multipart case the content is placed in a memory BIO |
@@ -444,13 +444,13 @@ ASN1_VALUE *SMIME_read_ASN1(BIO *bio, BIO **bcont, const ASN1_ITEM *it) | |||
444 | if (!(headers = mime_parse_hdr(bio))) { | 444 | if (!(headers = mime_parse_hdr(bio))) { |
445 | ASN1err(ASN1_F_SMIME_READ_ASN1,ASN1_R_MIME_PARSE_ERROR); | 445 | ASN1err(ASN1_F_SMIME_READ_ASN1,ASN1_R_MIME_PARSE_ERROR); |
446 | return NULL; | 446 | return NULL; |
447 | } | 447 | } |
448 | 448 | ||
449 | if(!(hdr = mime_hdr_find(headers, "content-type")) || !hdr->value) { | 449 | if(!(hdr = mime_hdr_find(headers, "content-type")) || !hdr->value) { |
450 | sk_MIME_HEADER_pop_free(headers, mime_hdr_free); | 450 | sk_MIME_HEADER_pop_free(headers, mime_hdr_free); |
451 | ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_NO_CONTENT_TYPE); | 451 | ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_NO_CONTENT_TYPE); |
452 | return NULL; | 452 | return NULL; |
453 | } | 453 | } |
454 | 454 | ||
455 | /* Handle multipart/signed */ | 455 | /* Handle multipart/signed */ |
456 | 456 | ||
@@ -461,14 +461,14 @@ ASN1_VALUE *SMIME_read_ASN1(BIO *bio, BIO **bcont, const ASN1_ITEM *it) | |||
461 | sk_MIME_HEADER_pop_free(headers, mime_hdr_free); | 461 | sk_MIME_HEADER_pop_free(headers, mime_hdr_free); |
462 | ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_NO_MULTIPART_BOUNDARY); | 462 | ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_NO_MULTIPART_BOUNDARY); |
463 | return NULL; | 463 | return NULL; |
464 | } | 464 | } |
465 | ret = multi_split(bio, prm->param_value, &parts); | 465 | ret = multi_split(bio, prm->param_value, &parts); |
466 | sk_MIME_HEADER_pop_free(headers, mime_hdr_free); | 466 | sk_MIME_HEADER_pop_free(headers, mime_hdr_free); |
467 | if(!ret || (sk_BIO_num(parts) != 2) ) { | 467 | if(!ret || (sk_BIO_num(parts) != 2) ) { |
468 | ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_NO_MULTIPART_BODY_FAILURE); | 468 | ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_NO_MULTIPART_BODY_FAILURE); |
469 | sk_BIO_pop_free(parts, BIO_vfree); | 469 | sk_BIO_pop_free(parts, BIO_vfree); |
470 | return NULL; | 470 | return NULL; |
471 | } | 471 | } |
472 | 472 | ||
473 | /* Parse the signature piece */ | 473 | /* Parse the signature piece */ |
474 | asnin = sk_BIO_value(parts, 1); | 474 | asnin = sk_BIO_value(parts, 1); |
@@ -477,7 +477,7 @@ ASN1_VALUE *SMIME_read_ASN1(BIO *bio, BIO **bcont, const ASN1_ITEM *it) | |||
477 | ASN1err(ASN1_F_SMIME_READ_ASN1,ASN1_R_MIME_SIG_PARSE_ERROR); | 477 | ASN1err(ASN1_F_SMIME_READ_ASN1,ASN1_R_MIME_SIG_PARSE_ERROR); |
478 | sk_BIO_pop_free(parts, BIO_vfree); | 478 | sk_BIO_pop_free(parts, BIO_vfree); |
479 | return NULL; | 479 | return NULL; |
480 | } | 480 | } |
481 | 481 | ||
482 | /* Get content type */ | 482 | /* Get content type */ |
483 | 483 | ||
@@ -486,7 +486,7 @@ ASN1_VALUE *SMIME_read_ASN1(BIO *bio, BIO **bcont, const ASN1_ITEM *it) | |||
486 | sk_MIME_HEADER_pop_free(headers, mime_hdr_free); | 486 | sk_MIME_HEADER_pop_free(headers, mime_hdr_free); |
487 | ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_NO_SIG_CONTENT_TYPE); | 487 | ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_NO_SIG_CONTENT_TYPE); |
488 | return NULL; | 488 | return NULL; |
489 | } | 489 | } |
490 | 490 | ||
491 | if(strcmp(hdr->value, "application/x-pkcs7-signature") && | 491 | if(strcmp(hdr->value, "application/x-pkcs7-signature") && |
492 | strcmp(hdr->value, "application/pkcs7-signature")) { | 492 | strcmp(hdr->value, "application/pkcs7-signature")) { |
@@ -495,22 +495,22 @@ ASN1_VALUE *SMIME_read_ASN1(BIO *bio, BIO **bcont, const ASN1_ITEM *it) | |||
495 | sk_MIME_HEADER_pop_free(headers, mime_hdr_free); | 495 | sk_MIME_HEADER_pop_free(headers, mime_hdr_free); |
496 | sk_BIO_pop_free(parts, BIO_vfree); | 496 | sk_BIO_pop_free(parts, BIO_vfree); |
497 | return NULL; | 497 | return NULL; |
498 | } | 498 | } |
499 | sk_MIME_HEADER_pop_free(headers, mime_hdr_free); | 499 | sk_MIME_HEADER_pop_free(headers, mime_hdr_free); |
500 | /* Read in ASN1 */ | 500 | /* Read in ASN1 */ |
501 | if(!(val = b64_read_asn1(asnin, it))) { | 501 | if(!(val = b64_read_asn1(asnin, it))) { |
502 | ASN1err(ASN1_F_SMIME_READ_ASN1,ASN1_R_ASN1_SIG_PARSE_ERROR); | 502 | ASN1err(ASN1_F_SMIME_READ_ASN1,ASN1_R_ASN1_SIG_PARSE_ERROR); |
503 | sk_BIO_pop_free(parts, BIO_vfree); | 503 | sk_BIO_pop_free(parts, BIO_vfree); |
504 | return NULL; | 504 | return NULL; |
505 | } | 505 | } |
506 | 506 | ||
507 | if(bcont) { | 507 | if(bcont) { |
508 | *bcont = sk_BIO_value(parts, 0); | 508 | *bcont = sk_BIO_value(parts, 0); |
509 | BIO_free(asnin); | 509 | BIO_free(asnin); |
510 | sk_BIO_free(parts); | 510 | sk_BIO_free(parts); |
511 | } else sk_BIO_pop_free(parts, BIO_vfree); | 511 | } else sk_BIO_pop_free(parts, BIO_vfree); |
512 | return val; | 512 | return val; |
513 | } | 513 | } |
514 | 514 | ||
515 | /* OK, if not multipart/signed try opaque signature */ | 515 | /* OK, if not multipart/signed try opaque signature */ |
516 | 516 | ||
@@ -520,14 +520,14 @@ ASN1_VALUE *SMIME_read_ASN1(BIO *bio, BIO **bcont, const ASN1_ITEM *it) | |||
520 | ERR_add_error_data(2, "type: ", hdr->value); | 520 | ERR_add_error_data(2, "type: ", hdr->value); |
521 | sk_MIME_HEADER_pop_free(headers, mime_hdr_free); | 521 | sk_MIME_HEADER_pop_free(headers, mime_hdr_free); |
522 | return NULL; | 522 | return NULL; |
523 | } | 523 | } |
524 | 524 | ||
525 | sk_MIME_HEADER_pop_free(headers, mime_hdr_free); | 525 | sk_MIME_HEADER_pop_free(headers, mime_hdr_free); |
526 | 526 | ||
527 | if(!(val = b64_read_asn1(bio, it))) { | 527 | if(!(val = b64_read_asn1(bio, it))) { |
528 | ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_ASN1_PARSE_ERROR); | 528 | ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_ASN1_PARSE_ERROR); |
529 | return NULL; | 529 | return NULL; |
530 | } | 530 | } |
531 | return val; | 531 | return val; |
532 | 532 | ||
533 | } | 533 | } |
@@ -548,22 +548,22 @@ int SMIME_crlf_copy(BIO *in, BIO *out, int flags) | |||
548 | return 0; | 548 | return 0; |
549 | out = BIO_push(bf, out); | 549 | out = BIO_push(bf, out); |
550 | if(flags & SMIME_BINARY) | 550 | if(flags & SMIME_BINARY) |
551 | { | 551 | { |
552 | while((len = BIO_read(in, linebuf, MAX_SMLEN)) > 0) | 552 | while((len = BIO_read(in, linebuf, MAX_SMLEN)) > 0) |
553 | BIO_write(out, linebuf, len); | 553 | BIO_write(out, linebuf, len); |
554 | } | 554 | } |
555 | else | 555 | else |
556 | { | 556 | { |
557 | if(flags & SMIME_TEXT) | 557 | if(flags & SMIME_TEXT) |
558 | BIO_printf(out, "Content-Type: text/plain\r\n\r\n"); | 558 | BIO_printf(out, "Content-Type: text/plain\r\n\r\n"); |
559 | while ((len = BIO_gets(in, linebuf, MAX_SMLEN)) > 0) | 559 | while ((len = BIO_gets(in, linebuf, MAX_SMLEN)) > 0) |
560 | { | 560 | { |
561 | eol = strip_eol(linebuf, &len); | 561 | eol = strip_eol(linebuf, &len); |
562 | if (len) | 562 | if (len) |
563 | BIO_write(out, linebuf, len); | 563 | BIO_write(out, linebuf, len); |
564 | if(eol) BIO_write(out, "\r\n", 2); | 564 | if(eol) BIO_write(out, "\r\n", 2); |
565 | } | ||
566 | } | 565 | } |
566 | } | ||
567 | (void)BIO_flush(out); | 567 | (void)BIO_flush(out); |
568 | BIO_pop(out); | 568 | BIO_pop(out); |
569 | BIO_free(bf); | 569 | BIO_free(bf); |
@@ -581,18 +581,18 @@ int SMIME_text(BIO *in, BIO *out) | |||
581 | if (!(headers = mime_parse_hdr(in))) { | 581 | if (!(headers = mime_parse_hdr(in))) { |
582 | ASN1err(ASN1_F_SMIME_TEXT,ASN1_R_MIME_PARSE_ERROR); | 582 | ASN1err(ASN1_F_SMIME_TEXT,ASN1_R_MIME_PARSE_ERROR); |
583 | return 0; | 583 | return 0; |
584 | } | 584 | } |
585 | if(!(hdr = mime_hdr_find(headers, "content-type")) || !hdr->value) { | 585 | if(!(hdr = mime_hdr_find(headers, "content-type")) || !hdr->value) { |
586 | ASN1err(ASN1_F_SMIME_TEXT,ASN1_R_MIME_NO_CONTENT_TYPE); | 586 | ASN1err(ASN1_F_SMIME_TEXT,ASN1_R_MIME_NO_CONTENT_TYPE); |
587 | sk_MIME_HEADER_pop_free(headers, mime_hdr_free); | 587 | sk_MIME_HEADER_pop_free(headers, mime_hdr_free); |
588 | return 0; | 588 | return 0; |
589 | } | 589 | } |
590 | if (strcmp (hdr->value, "text/plain")) { | 590 | if (strcmp (hdr->value, "text/plain")) { |
591 | ASN1err(ASN1_F_SMIME_TEXT,ASN1_R_INVALID_MIME_TYPE); | 591 | ASN1err(ASN1_F_SMIME_TEXT,ASN1_R_INVALID_MIME_TYPE); |
592 | ERR_add_error_data(2, "type: ", hdr->value); | 592 | ERR_add_error_data(2, "type: ", hdr->value); |
593 | sk_MIME_HEADER_pop_free(headers, mime_hdr_free); | 593 | sk_MIME_HEADER_pop_free(headers, mime_hdr_free); |
594 | return 0; | 594 | return 0; |
595 | } | 595 | } |
596 | sk_MIME_HEADER_pop_free(headers, mime_hdr_free); | 596 | sk_MIME_HEADER_pop_free(headers, mime_hdr_free); |
597 | while ((len = BIO_read(in, iobuf, sizeof(iobuf))) > 0) | 597 | while ((len = BIO_read(in, iobuf, sizeof(iobuf))) > 0) |
598 | BIO_write(out, iobuf, len); | 598 | BIO_write(out, iobuf, len); |
@@ -625,10 +625,10 @@ static int multi_split(BIO *bio, char *bound, STACK_OF(BIO) **ret) | |||
625 | if(state == 1) { | 625 | if(state == 1) { |
626 | first = 1; | 626 | first = 1; |
627 | part++; | 627 | part++; |
628 | } else if(state == 2) { | 628 | } else if(state == 2) { |
629 | sk_BIO_push(parts, bpart); | 629 | sk_BIO_push(parts, bpart); |
630 | return 1; | 630 | return 1; |
631 | } else if(part) { | 631 | } else if(part) { |
632 | /* Strip CR+LF from linebuf */ | 632 | /* Strip CR+LF from linebuf */ |
633 | next_eol = strip_eol(linebuf, &len); | 633 | next_eol = strip_eol(linebuf, &len); |
634 | if(first) { | 634 | if(first) { |
@@ -636,13 +636,13 @@ static int multi_split(BIO *bio, char *bound, STACK_OF(BIO) **ret) | |||
636 | if(bpart) sk_BIO_push(parts, bpart); | 636 | if(bpart) sk_BIO_push(parts, bpart); |
637 | bpart = BIO_new(BIO_s_mem()); | 637 | bpart = BIO_new(BIO_s_mem()); |
638 | BIO_set_mem_eof_return(bpart, 0); | 638 | BIO_set_mem_eof_return(bpart, 0); |
639 | } else if (eol) | 639 | } else if (eol) |
640 | BIO_write(bpart, "\r\n", 2); | 640 | BIO_write(bpart, "\r\n", 2); |
641 | eol = next_eol; | 641 | eol = next_eol; |
642 | if (len) | 642 | if (len) |
643 | BIO_write(bpart, linebuf, len); | 643 | BIO_write(bpart, linebuf, len); |
644 | } | ||
645 | } | 644 | } |
645 | } | ||
646 | return 0; | 646 | return 0; |
647 | } | 647 | } |
648 | 648 | ||
@@ -686,7 +686,7 @@ static STACK_OF(MIME_HEADER) *mime_parse_hdr(BIO *bio) | |||
686 | *p = 0; | 686 | *p = 0; |
687 | ntmp = strip_ends(q); | 687 | ntmp = strip_ends(q); |
688 | q = p + 1; | 688 | q = p + 1; |
689 | } | 689 | } |
690 | break; | 690 | break; |
691 | 691 | ||
692 | case MIME_TYPE: | 692 | case MIME_TYPE: |
@@ -698,16 +698,16 @@ static STACK_OF(MIME_HEADER) *mime_parse_hdr(BIO *bio) | |||
698 | ntmp = NULL; | 698 | ntmp = NULL; |
699 | q = p + 1; | 699 | q = p + 1; |
700 | state = MIME_NAME; | 700 | state = MIME_NAME; |
701 | } else if(c == '(') { | 701 | } else if(c == '(') { |
702 | save_state = state; | 702 | save_state = state; |
703 | state = MIME_COMMENT; | 703 | state = MIME_COMMENT; |
704 | } | 704 | } |
705 | break; | 705 | break; |
706 | 706 | ||
707 | case MIME_COMMENT: | 707 | case MIME_COMMENT: |
708 | if(c == ')') { | 708 | if(c == ')') { |
709 | state = save_state; | 709 | state = save_state; |
710 | } | 710 | } |
711 | break; | 711 | break; |
712 | 712 | ||
713 | case MIME_NAME: | 713 | case MIME_NAME: |
@@ -716,7 +716,7 @@ static STACK_OF(MIME_HEADER) *mime_parse_hdr(BIO *bio) | |||
716 | *p = 0; | 716 | *p = 0; |
717 | ntmp = strip_ends(q); | 717 | ntmp = strip_ends(q); |
718 | q = p + 1; | 718 | q = p + 1; |
719 | } | 719 | } |
720 | break ; | 720 | break ; |
721 | 721 | ||
722 | case MIME_VALUE: | 722 | case MIME_VALUE: |
@@ -726,28 +726,28 @@ static STACK_OF(MIME_HEADER) *mime_parse_hdr(BIO *bio) | |||
726 | mime_hdr_addparam(mhdr, ntmp, strip_ends(q)); | 726 | mime_hdr_addparam(mhdr, ntmp, strip_ends(q)); |
727 | ntmp = NULL; | 727 | ntmp = NULL; |
728 | q = p + 1; | 728 | q = p + 1; |
729 | } else if (c == '"') { | 729 | } else if (c == '"') { |
730 | mime_debug("Found Quote\n"); | 730 | mime_debug("Found Quote\n"); |
731 | state = MIME_QUOTE; | 731 | state = MIME_QUOTE; |
732 | } else if(c == '(') { | 732 | } else if(c == '(') { |
733 | save_state = state; | 733 | save_state = state; |
734 | state = MIME_COMMENT; | 734 | state = MIME_COMMENT; |
735 | } | 735 | } |
736 | break; | 736 | break; |
737 | 737 | ||
738 | case MIME_QUOTE: | 738 | case MIME_QUOTE: |
739 | if(c == '"') { | 739 | if(c == '"') { |
740 | mime_debug("Found Match Quote\n"); | 740 | mime_debug("Found Match Quote\n"); |
741 | state = MIME_VALUE; | 741 | state = MIME_VALUE; |
742 | } | ||
743 | break; | ||
744 | } | 742 | } |
743 | break; | ||
745 | } | 744 | } |
745 | } | ||
746 | 746 | ||
747 | if(state == MIME_TYPE) { | 747 | if(state == MIME_TYPE) { |
748 | mhdr = mime_hdr_new(ntmp, strip_ends(q)); | 748 | mhdr = mime_hdr_new(ntmp, strip_ends(q)); |
749 | sk_MIME_HEADER_push(headers, mhdr); | 749 | sk_MIME_HEADER_push(headers, mhdr); |
750 | } else if(state == MIME_VALUE) | 750 | } else if(state == MIME_VALUE) |
751 | mime_hdr_addparam(mhdr, ntmp, strip_ends(q)); | 751 | mime_hdr_addparam(mhdr, ntmp, strip_ends(q)); |
752 | if(p == linebuf) break; /* Blank line means end of headers */ | 752 | if(p == linebuf) break; /* Blank line means end of headers */ |
753 | } | 753 | } |
@@ -772,9 +772,9 @@ static char *strip_start(char *name) | |||
772 | if(p[1]) return p + 1; | 772 | if(p[1]) return p + 1; |
773 | /* Else null string */ | 773 | /* Else null string */ |
774 | return NULL; | 774 | return NULL; |
775 | } | ||
776 | if(!isspace((unsigned char)c)) return p; | ||
777 | } | 775 | } |
776 | if(!isspace((unsigned char)c)) return p; | ||
777 | } | ||
778 | return NULL; | 778 | return NULL; |
779 | } | 779 | } |
780 | 780 | ||
@@ -790,10 +790,10 @@ static char *strip_end(char *name) | |||
790 | if(p - 1 == name) return NULL; | 790 | if(p - 1 == name) return NULL; |
791 | *p = 0; | 791 | *p = 0; |
792 | return name; | 792 | return name; |
793 | } | 793 | } |
794 | if(isspace((unsigned char)c)) *p = 0; | 794 | if(isspace((unsigned char)c)) *p = 0; |
795 | else return name; | 795 | else return name; |
796 | } | 796 | } |
797 | return NULL; | 797 | return NULL; |
798 | } | 798 | } |
799 | 799 | ||
@@ -809,9 +809,9 @@ static MIME_HEADER *mime_hdr_new(char *name, char *value) | |||
809 | if(isupper(c)) { | 809 | if(isupper(c)) { |
810 | c = tolower(c); | 810 | c = tolower(c); |
811 | *p = c; | 811 | *p = c; |
812 | } | ||
813 | } | 812 | } |
814 | } else tmpname = NULL; | 813 | } |
814 | } else tmpname = NULL; | ||
815 | if(value) { | 815 | if(value) { |
816 | if(!(tmpval = BUF_strdup(value))) return NULL; | 816 | if(!(tmpval = BUF_strdup(value))) return NULL; |
817 | for(p = tmpval ; *p; p++) { | 817 | for(p = tmpval ; *p; p++) { |
@@ -819,20 +819,20 @@ static MIME_HEADER *mime_hdr_new(char *name, char *value) | |||
819 | if(isupper(c)) { | 819 | if(isupper(c)) { |
820 | c = tolower(c); | 820 | c = tolower(c); |
821 | *p = c; | 821 | *p = c; |
822 | } | ||
823 | } | 822 | } |
824 | } else tmpval = NULL; | 823 | } |
824 | } else tmpval = NULL; | ||
825 | mhdr = (MIME_HEADER *) malloc(sizeof(MIME_HEADER)); | 825 | mhdr = (MIME_HEADER *) malloc(sizeof(MIME_HEADER)); |
826 | if (!mhdr) { | 826 | if (!mhdr) { |
827 | OPENSSL_free(tmpname); | 827 | OPENSSL_free(tmpname); |
828 | return NULL; | 828 | return NULL; |
829 | } | 829 | } |
830 | mhdr->name = tmpname; | 830 | mhdr->name = tmpname; |
831 | mhdr->value = tmpval; | 831 | mhdr->value = tmpval; |
832 | if (!(mhdr->params = sk_MIME_PARAM_new(mime_param_cmp))) { | 832 | if (!(mhdr->params = sk_MIME_PARAM_new(mime_param_cmp))) { |
833 | free(mhdr); | 833 | free(mhdr); |
834 | return NULL; | 834 | return NULL; |
835 | } | 835 | } |
836 | return mhdr; | 836 | return mhdr; |
837 | } | 837 | } |
838 | 838 | ||
@@ -849,13 +849,13 @@ static int mime_hdr_addparam(MIME_HEADER *mhdr, char *name, char *value) | |||
849 | if(isupper(c)) { | 849 | if(isupper(c)) { |
850 | c = tolower(c); | 850 | c = tolower(c); |
851 | *p = c; | 851 | *p = c; |
852 | } | ||
853 | } | 852 | } |
854 | } else tmpname = NULL; | 853 | } |
854 | } else tmpname = NULL; | ||
855 | if(value) { | 855 | if(value) { |
856 | tmpval = BUF_strdup(value); | 856 | tmpval = BUF_strdup(value); |
857 | if(!tmpval) return 0; | 857 | if(!tmpval) return 0; |
858 | } else tmpval = NULL; | 858 | } else tmpval = NULL; |
859 | /* Parameter values are case sensitive so leave as is */ | 859 | /* Parameter values are case sensitive so leave as is */ |
860 | mparam = (MIME_PARAM *) malloc(sizeof(MIME_PARAM)); | 860 | mparam = (MIME_PARAM *) malloc(sizeof(MIME_PARAM)); |
861 | if(!mparam) return 0; | 861 | if(!mparam) return 0; |
@@ -934,24 +934,24 @@ static int mime_bound_check(char *line, int linelen, char *bound, int blen) | |||
934 | if(!strncmp(line, "--", 2) && !strncmp(line + 2, bound, blen)) { | 934 | if(!strncmp(line, "--", 2) && !strncmp(line + 2, bound, blen)) { |
935 | if(!strncmp(line + blen + 2, "--", 2)) return 2; | 935 | if(!strncmp(line + blen + 2, "--", 2)) return 2; |
936 | else return 1; | 936 | else return 1; |
937 | } | 937 | } |
938 | return 0; | 938 | return 0; |
939 | } | 939 | } |
940 | 940 | ||
941 | static int strip_eol(char *linebuf, int *plen) | 941 | static int strip_eol(char *linebuf, int *plen) |
942 | { | 942 | { |
943 | int len = *plen; | 943 | int len = *plen; |
944 | char *p, c; | 944 | char *p, c; |
945 | int is_eol = 0; | 945 | int is_eol = 0; |
946 | p = linebuf + len - 1; | 946 | p = linebuf + len - 1; |
947 | for (p = linebuf + len - 1; len > 0; len--, p--) | 947 | for (p = linebuf + len - 1; len > 0; len--, p--) |
948 | { | 948 | { |
949 | c = *p; | 949 | c = *p; |
950 | if (c == '\n') | 950 | if (c == '\n') |
951 | is_eol = 1; | 951 | is_eol = 1; |
952 | else if (c != '\r') | 952 | else if (c != '\r') |
953 | break; | 953 | break; |
954 | } | 954 | } |
955 | *plen = len; | 955 | *plen = len; |
956 | return is_eol; | 956 | return is_eol; |
957 | } | 957 | } |
diff --git a/src/lib/libssl/src/crypto/asn1/asn_moid.c b/src/lib/libssl/src/crypto/asn1/asn_moid.c index fd04d11459..7521496d67 100644 --- a/src/lib/libssl/src/crypto/asn1/asn_moid.c +++ b/src/lib/libssl/src/crypto/asn1/asn_moid.c | |||
@@ -69,38 +69,38 @@ | |||
69 | static int do_create(char *value, char *name); | 69 | static int do_create(char *value, char *name); |
70 | 70 | ||
71 | static int oid_module_init(CONF_IMODULE *md, const CONF *cnf) | 71 | static int oid_module_init(CONF_IMODULE *md, const CONF *cnf) |
72 | { | 72 | { |
73 | int i; | 73 | int i; |
74 | const char *oid_section; | 74 | const char *oid_section; |
75 | STACK_OF(CONF_VALUE) *sktmp; | 75 | STACK_OF(CONF_VALUE) *sktmp; |
76 | CONF_VALUE *oval; | 76 | CONF_VALUE *oval; |
77 | oid_section = CONF_imodule_get_value(md); | 77 | oid_section = CONF_imodule_get_value(md); |
78 | if(!(sktmp = NCONF_get_section(cnf, oid_section))) | 78 | if(!(sktmp = NCONF_get_section(cnf, oid_section))) |
79 | { | 79 | { |
80 | ASN1err(ASN1_F_OID_MODULE_INIT, ASN1_R_ERROR_LOADING_SECTION); | 80 | ASN1err(ASN1_F_OID_MODULE_INIT, ASN1_R_ERROR_LOADING_SECTION); |
81 | return 0; | 81 | return 0; |
82 | } | 82 | } |
83 | for(i = 0; i < sk_CONF_VALUE_num(sktmp); i++) | 83 | for(i = 0; i < sk_CONF_VALUE_num(sktmp); i++) |
84 | { | 84 | { |
85 | oval = sk_CONF_VALUE_value(sktmp, i); | 85 | oval = sk_CONF_VALUE_value(sktmp, i); |
86 | if(!do_create(oval->value, oval->name)) | 86 | if(!do_create(oval->value, oval->name)) |
87 | { | 87 | { |
88 | ASN1err(ASN1_F_OID_MODULE_INIT, ASN1_R_ADDING_OBJECT); | 88 | ASN1err(ASN1_F_OID_MODULE_INIT, ASN1_R_ADDING_OBJECT); |
89 | return 0; | 89 | return 0; |
90 | } | ||
91 | } | 90 | } |
92 | return 1; | ||
93 | } | 91 | } |
92 | return 1; | ||
93 | } | ||
94 | 94 | ||
95 | static void oid_module_finish(CONF_IMODULE *md) | 95 | static void oid_module_finish(CONF_IMODULE *md) |
96 | { | 96 | { |
97 | OBJ_cleanup(); | 97 | OBJ_cleanup(); |
98 | } | 98 | } |
99 | 99 | ||
100 | void ASN1_add_oid_module(void) | 100 | void ASN1_add_oid_module(void) |
101 | { | 101 | { |
102 | CONF_module_add("oid_section", oid_module_init, oid_module_finish); | 102 | CONF_module_add("oid_section", oid_module_init, oid_module_finish); |
103 | } | 103 | } |
104 | 104 | ||
105 | /* Create an OID based on a name value pair. Accept two formats. | 105 | /* Create an OID based on a name value pair. Accept two formats. |
106 | * shortname = 1.2.3.4 | 106 | * shortname = 1.2.3.4 |
@@ -109,24 +109,24 @@ void ASN1_add_oid_module(void) | |||
109 | 109 | ||
110 | 110 | ||
111 | static int do_create(char *value, char *name) | 111 | static int do_create(char *value, char *name) |
112 | { | 112 | { |
113 | int nid; | 113 | int nid; |
114 | ASN1_OBJECT *oid; | 114 | ASN1_OBJECT *oid; |
115 | char *ln, *ostr, *p, *lntmp; | 115 | char *ln, *ostr, *p, *lntmp; |
116 | p = strrchr(value, ','); | 116 | p = strrchr(value, ','); |
117 | if (!p) | 117 | if (!p) |
118 | { | 118 | { |
119 | ln = name; | 119 | ln = name; |
120 | ostr = value; | 120 | ostr = value; |
121 | } | 121 | } |
122 | else | 122 | else |
123 | { | 123 | { |
124 | ln = NULL; | 124 | ln = NULL; |
125 | ostr = p + 1; | 125 | ostr = p + 1; |
126 | if (!*ostr) | 126 | if (!*ostr) |
127 | return 0; | 127 | return 0; |
128 | while(isspace((unsigned char)*ostr)) ostr++; | 128 | while(isspace((unsigned char)*ostr)) ostr++; |
129 | } | 129 | } |
130 | 130 | ||
131 | nid = OBJ_create(ostr, name, ln); | 131 | nid = OBJ_create(ostr, name, ln); |
132 | 132 | ||
@@ -134,16 +134,16 @@ static int do_create(char *value, char *name) | |||
134 | return 0; | 134 | return 0; |
135 | 135 | ||
136 | if (p) | 136 | if (p) |
137 | { | 137 | { |
138 | ln = value; | 138 | ln = value; |
139 | while(isspace((unsigned char)*ln)) ln++; | 139 | while(isspace((unsigned char)*ln)) ln++; |
140 | p--; | 140 | p--; |
141 | while(isspace((unsigned char)*p)) | 141 | while(isspace((unsigned char)*p)) |
142 | { | 142 | { |
143 | if (p == ln) | 143 | if (p == ln) |
144 | return 0; | 144 | return 0; |
145 | p--; | 145 | p--; |
146 | } | 146 | } |
147 | p++; | 147 | p++; |
148 | lntmp = malloc((p - ln) + 1); | 148 | lntmp = malloc((p - ln) + 1); |
149 | if (lntmp == NULL) | 149 | if (lntmp == NULL) |
@@ -152,9 +152,9 @@ static int do_create(char *value, char *name) | |||
152 | lntmp[p - ln] = 0; | 152 | lntmp[p - ln] = 0; |
153 | oid = OBJ_nid2obj(nid); | 153 | oid = OBJ_nid2obj(nid); |
154 | oid->ln = lntmp; | 154 | oid->ln = lntmp; |
155 | } | 155 | } |
156 | 156 | ||
157 | return 1; | 157 | return 1; |
158 | } | 158 | } |
159 | 159 | ||
160 | 160 | ||
diff --git a/src/lib/libssl/src/crypto/asn1/bio_asn1.c b/src/lib/libssl/src/crypto/asn1/bio_asn1.c index b59645909c..a6ad850e46 100644 --- a/src/lib/libssl/src/crypto/asn1/bio_asn1.c +++ b/src/lib/libssl/src/crypto/asn1/bio_asn1.c | |||
@@ -69,7 +69,7 @@ | |||
69 | #define DEFAULT_ASN1_BUF_SIZE 20 | 69 | #define DEFAULT_ASN1_BUF_SIZE 20 |
70 | 70 | ||
71 | typedef enum | 71 | typedef enum |
72 | { | 72 | { |
73 | ASN1_STATE_START, | 73 | ASN1_STATE_START, |
74 | ASN1_STATE_PRE_COPY, | 74 | ASN1_STATE_PRE_COPY, |
75 | ASN1_STATE_HEADER, | 75 | ASN1_STATE_HEADER, |
@@ -77,16 +77,16 @@ typedef enum | |||
77 | ASN1_STATE_DATA_COPY, | 77 | ASN1_STATE_DATA_COPY, |
78 | ASN1_STATE_POST_COPY, | 78 | ASN1_STATE_POST_COPY, |
79 | ASN1_STATE_DONE | 79 | ASN1_STATE_DONE |
80 | } asn1_bio_state_t; | 80 | } asn1_bio_state_t; |
81 | 81 | ||
82 | typedef struct BIO_ASN1_EX_FUNCS_st | 82 | typedef struct BIO_ASN1_EX_FUNCS_st |
83 | { | 83 | { |
84 | asn1_ps_func *ex_func; | 84 | asn1_ps_func *ex_func; |
85 | asn1_ps_func *ex_free_func; | 85 | asn1_ps_func *ex_free_func; |
86 | } BIO_ASN1_EX_FUNCS; | 86 | } BIO_ASN1_EX_FUNCS; |
87 | 87 | ||
88 | typedef struct BIO_ASN1_BUF_CTX_t | 88 | typedef struct BIO_ASN1_BUF_CTX_t |
89 | { | 89 | { |
90 | /* Internal state */ | 90 | /* Internal state */ |
91 | asn1_bio_state_t state; | 91 | asn1_bio_state_t state; |
92 | /* Internal buffer */ | 92 | /* Internal buffer */ |
@@ -107,7 +107,7 @@ typedef struct BIO_ASN1_BUF_CTX_t | |||
107 | int ex_len; | 107 | int ex_len; |
108 | int ex_pos; | 108 | int ex_pos; |
109 | void *ex_arg; | 109 | void *ex_arg; |
110 | } BIO_ASN1_BUF_CTX; | 110 | } BIO_ASN1_BUF_CTX; |
111 | 111 | ||
112 | 112 | ||
113 | static int asn1_bio_write(BIO *h, const char *buf,int num); | 113 | static int asn1_bio_write(BIO *h, const char *buf,int num); |
@@ -128,7 +128,7 @@ static int asn1_bio_setup_ex(BIO *b, BIO_ASN1_BUF_CTX *ctx, | |||
128 | asn1_bio_state_t other_state); | 128 | asn1_bio_state_t other_state); |
129 | 129 | ||
130 | static BIO_METHOD methods_asn1= | 130 | static BIO_METHOD methods_asn1= |
131 | { | 131 | { |
132 | BIO_TYPE_ASN1, | 132 | BIO_TYPE_ASN1, |
133 | "asn1", | 133 | "asn1", |
134 | asn1_bio_write, | 134 | asn1_bio_write, |
@@ -139,16 +139,16 @@ static BIO_METHOD methods_asn1= | |||
139 | asn1_bio_new, | 139 | asn1_bio_new, |
140 | asn1_bio_free, | 140 | asn1_bio_free, |
141 | asn1_bio_callback_ctrl, | 141 | asn1_bio_callback_ctrl, |
142 | }; | 142 | }; |
143 | 143 | ||
144 | BIO_METHOD *BIO_f_asn1(void) | 144 | BIO_METHOD *BIO_f_asn1(void) |
145 | { | 145 | { |
146 | return(&methods_asn1); | 146 | return(&methods_asn1); |
147 | } | 147 | } |
148 | 148 | ||
149 | 149 | ||
150 | static int asn1_bio_new(BIO *b) | 150 | static int asn1_bio_new(BIO *b) |
151 | { | 151 | { |
152 | BIO_ASN1_BUF_CTX *ctx; | 152 | BIO_ASN1_BUF_CTX *ctx; |
153 | ctx = malloc(sizeof(BIO_ASN1_BUF_CTX)); | 153 | ctx = malloc(sizeof(BIO_ASN1_BUF_CTX)); |
154 | if (!ctx) | 154 | if (!ctx) |
@@ -156,15 +156,15 @@ static int asn1_bio_new(BIO *b) | |||
156 | if (!asn1_bio_init(ctx, DEFAULT_ASN1_BUF_SIZE)) { | 156 | if (!asn1_bio_init(ctx, DEFAULT_ASN1_BUF_SIZE)) { |
157 | free(ctx); | 157 | free(ctx); |
158 | return 0; | 158 | return 0; |
159 | } | 159 | } |
160 | b->init = 1; | 160 | b->init = 1; |
161 | b->ptr = (char *)ctx; | 161 | b->ptr = (char *)ctx; |
162 | b->flags = 0; | 162 | b->flags = 0; |
163 | return 1; | 163 | return 1; |
164 | } | 164 | } |
165 | 165 | ||
166 | static int asn1_bio_init(BIO_ASN1_BUF_CTX *ctx, int size) | 166 | static int asn1_bio_init(BIO_ASN1_BUF_CTX *ctx, int size) |
167 | { | 167 | { |
168 | ctx->buf = malloc(size); | 168 | ctx->buf = malloc(size); |
169 | if (!ctx->buf) | 169 | if (!ctx->buf) |
170 | return 0; | 170 | return 0; |
@@ -179,10 +179,10 @@ static int asn1_bio_init(BIO_ASN1_BUF_CTX *ctx, int size) | |||
179 | ctx->ex_len = 0; | 179 | ctx->ex_len = 0; |
180 | ctx->state = ASN1_STATE_START; | 180 | ctx->state = ASN1_STATE_START; |
181 | return 1; | 181 | return 1; |
182 | } | 182 | } |
183 | 183 | ||
184 | static int asn1_bio_free(BIO *b) | 184 | static int asn1_bio_free(BIO *b) |
185 | { | 185 | { |
186 | BIO_ASN1_BUF_CTX *ctx; | 186 | BIO_ASN1_BUF_CTX *ctx; |
187 | ctx = (BIO_ASN1_BUF_CTX *) b->ptr; | 187 | ctx = (BIO_ASN1_BUF_CTX *) b->ptr; |
188 | if (ctx == NULL) | 188 | if (ctx == NULL) |
@@ -194,10 +194,10 @@ static int asn1_bio_free(BIO *b) | |||
194 | b->ptr = NULL; | 194 | b->ptr = NULL; |
195 | b->flags = 0; | 195 | b->flags = 0; |
196 | return 1; | 196 | return 1; |
197 | } | 197 | } |
198 | 198 | ||
199 | static int asn1_bio_write(BIO *b, const char *in , int inl) | 199 | static int asn1_bio_write(BIO *b, const char *in , int inl) |
200 | { | 200 | { |
201 | BIO_ASN1_BUF_CTX *ctx; | 201 | BIO_ASN1_BUF_CTX *ctx; |
202 | int wrmax, wrlen, ret; | 202 | int wrmax, wrlen, ret; |
203 | unsigned char *p; | 203 | unsigned char *p; |
@@ -211,9 +211,9 @@ static int asn1_bio_write(BIO *b, const char *in , int inl) | |||
211 | ret = -1; | 211 | ret = -1; |
212 | 212 | ||
213 | for(;;) | 213 | for(;;) |
214 | { | 214 | { |
215 | switch (ctx->state) | 215 | switch (ctx->state) |
216 | { | 216 | { |
217 | 217 | ||
218 | /* Setup prefix data, call it */ | 218 | /* Setup prefix data, call it */ |
219 | case ASN1_STATE_START: | 219 | case ASN1_STATE_START: |
@@ -255,10 +255,10 @@ static int asn1_bio_write(BIO *b, const char *in , int inl) | |||
255 | if (ctx->buflen) | 255 | if (ctx->buflen) |
256 | ctx->bufpos += ret; | 256 | ctx->bufpos += ret; |
257 | else | 257 | else |
258 | { | 258 | { |
259 | ctx->bufpos = 0; | 259 | ctx->bufpos = 0; |
260 | ctx->state = ASN1_STATE_DATA_COPY; | 260 | ctx->state = ASN1_STATE_DATA_COPY; |
261 | } | 261 | } |
262 | 262 | ||
263 | break; | 263 | break; |
264 | 264 | ||
@@ -288,26 +288,26 @@ static int asn1_bio_write(BIO *b, const char *in , int inl) | |||
288 | BIO_clear_retry_flags(b); | 288 | BIO_clear_retry_flags(b); |
289 | return 0; | 289 | return 0; |
290 | 290 | ||
291 | } | ||
292 | |||
293 | } | 291 | } |
294 | 292 | ||
293 | } | ||
294 | |||
295 | done: | 295 | done: |
296 | BIO_clear_retry_flags(b); | 296 | BIO_clear_retry_flags(b); |
297 | BIO_copy_next_retry(b); | 297 | BIO_copy_next_retry(b); |
298 | 298 | ||
299 | return (wrlen > 0) ? wrlen : ret; | 299 | return (wrlen > 0) ? wrlen : ret; |
300 | 300 | ||
301 | } | 301 | } |
302 | 302 | ||
303 | static int asn1_bio_flush_ex(BIO *b, BIO_ASN1_BUF_CTX *ctx, | 303 | static int asn1_bio_flush_ex(BIO *b, BIO_ASN1_BUF_CTX *ctx, |
304 | asn1_ps_func *cleanup, asn1_bio_state_t next) | 304 | asn1_ps_func *cleanup, asn1_bio_state_t next) |
305 | { | 305 | { |
306 | int ret; | 306 | int ret; |
307 | if (ctx->ex_len <= 0) | 307 | if (ctx->ex_len <= 0) |
308 | return 1; | 308 | return 1; |
309 | for(;;) | 309 | for(;;) |
310 | { | 310 | { |
311 | ret = BIO_write(b->next_bio, ctx->ex_buf + ctx->ex_pos, | 311 | ret = BIO_write(b->next_bio, ctx->ex_buf + ctx->ex_pos, |
312 | ctx->ex_len); | 312 | ctx->ex_len); |
313 | if (ret <= 0) | 313 | if (ret <= 0) |
@@ -316,62 +316,62 @@ static int asn1_bio_flush_ex(BIO *b, BIO_ASN1_BUF_CTX *ctx, | |||
316 | if (ctx->ex_len > 0) | 316 | if (ctx->ex_len > 0) |
317 | ctx->ex_pos += ret; | 317 | ctx->ex_pos += ret; |
318 | else | 318 | else |
319 | { | 319 | { |
320 | if(cleanup) | 320 | if(cleanup) |
321 | cleanup(b, &ctx->ex_buf, &ctx->ex_len, | 321 | cleanup(b, &ctx->ex_buf, &ctx->ex_len, |
322 | &ctx->ex_arg); | 322 | &ctx->ex_arg); |
323 | ctx->state = next; | 323 | ctx->state = next; |
324 | ctx->ex_pos = 0; | 324 | ctx->ex_pos = 0; |
325 | break; | 325 | break; |
326 | } | ||
327 | } | 326 | } |
328 | return ret; | ||
329 | } | 327 | } |
328 | return ret; | ||
329 | } | ||
330 | 330 | ||
331 | static int asn1_bio_setup_ex(BIO *b, BIO_ASN1_BUF_CTX *ctx, | 331 | static int asn1_bio_setup_ex(BIO *b, BIO_ASN1_BUF_CTX *ctx, |
332 | asn1_ps_func *setup, | 332 | asn1_ps_func *setup, |
333 | asn1_bio_state_t ex_state, | 333 | asn1_bio_state_t ex_state, |
334 | asn1_bio_state_t other_state) | 334 | asn1_bio_state_t other_state) |
335 | { | 335 | { |
336 | if (setup && !setup(b, &ctx->ex_buf, &ctx->ex_len, &ctx->ex_arg)) | 336 | if (setup && !setup(b, &ctx->ex_buf, &ctx->ex_len, &ctx->ex_arg)) |
337 | { | 337 | { |
338 | BIO_clear_retry_flags(b); | 338 | BIO_clear_retry_flags(b); |
339 | return 0; | 339 | return 0; |
340 | } | 340 | } |
341 | if (ctx->ex_len > 0) | 341 | if (ctx->ex_len > 0) |
342 | ctx->state = ex_state; | 342 | ctx->state = ex_state; |
343 | else | 343 | else |
344 | ctx->state = other_state; | 344 | ctx->state = other_state; |
345 | return 1; | 345 | return 1; |
346 | } | 346 | } |
347 | 347 | ||
348 | static int asn1_bio_read(BIO *b, char *in , int inl) | 348 | static int asn1_bio_read(BIO *b, char *in , int inl) |
349 | { | 349 | { |
350 | if (!b->next_bio) | 350 | if (!b->next_bio) |
351 | return 0; | 351 | return 0; |
352 | return BIO_read(b->next_bio, in , inl); | 352 | return BIO_read(b->next_bio, in , inl); |
353 | } | 353 | } |
354 | 354 | ||
355 | static int asn1_bio_puts(BIO *b, const char *str) | 355 | static int asn1_bio_puts(BIO *b, const char *str) |
356 | { | 356 | { |
357 | return asn1_bio_write(b, str, strlen(str)); | 357 | return asn1_bio_write(b, str, strlen(str)); |
358 | } | 358 | } |
359 | 359 | ||
360 | static int asn1_bio_gets(BIO *b, char *str, int size) | 360 | static int asn1_bio_gets(BIO *b, char *str, int size) |
361 | { | 361 | { |
362 | if (!b->next_bio) | 362 | if (!b->next_bio) |
363 | return 0; | 363 | return 0; |
364 | return BIO_gets(b->next_bio, str , size); | 364 | return BIO_gets(b->next_bio, str , size); |
365 | } | 365 | } |
366 | 366 | ||
367 | static long asn1_bio_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) | 367 | static long asn1_bio_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) |
368 | { | 368 | { |
369 | if (b->next_bio == NULL) return(0); | 369 | if (b->next_bio == NULL) return(0); |
370 | return BIO_callback_ctrl(b->next_bio,cmd,fp); | 370 | return BIO_callback_ctrl(b->next_bio,cmd,fp); |
371 | } | 371 | } |
372 | 372 | ||
373 | static long asn1_bio_ctrl(BIO *b, int cmd, long arg1, void *arg2) | 373 | static long asn1_bio_ctrl(BIO *b, int cmd, long arg1, void *arg2) |
374 | { | 374 | { |
375 | BIO_ASN1_BUF_CTX *ctx; | 375 | BIO_ASN1_BUF_CTX *ctx; |
376 | BIO_ASN1_EX_FUNCS *ex_func; | 376 | BIO_ASN1_EX_FUNCS *ex_func; |
377 | long ret = 1; | 377 | long ret = 1; |
@@ -379,7 +379,7 @@ static long asn1_bio_ctrl(BIO *b, int cmd, long arg1, void *arg2) | |||
379 | if (ctx == NULL) | 379 | if (ctx == NULL) |
380 | return 0; | 380 | return 0; |
381 | switch(cmd) | 381 | switch(cmd) |
382 | { | 382 | { |
383 | 383 | ||
384 | case BIO_C_SET_PREFIX: | 384 | case BIO_C_SET_PREFIX: |
385 | ex_func = arg2; | 385 | ex_func = arg2; |
@@ -419,27 +419,27 @@ static long asn1_bio_ctrl(BIO *b, int cmd, long arg1, void *arg2) | |||
419 | 419 | ||
420 | /* Call post function if possible */ | 420 | /* Call post function if possible */ |
421 | if (ctx->state == ASN1_STATE_HEADER) | 421 | if (ctx->state == ASN1_STATE_HEADER) |
422 | { | 422 | { |
423 | if (!asn1_bio_setup_ex(b, ctx, ctx->suffix, | 423 | if (!asn1_bio_setup_ex(b, ctx, ctx->suffix, |
424 | ASN1_STATE_POST_COPY, ASN1_STATE_DONE)) | 424 | ASN1_STATE_POST_COPY, ASN1_STATE_DONE)) |
425 | return 0; | 425 | return 0; |
426 | } | 426 | } |
427 | 427 | ||
428 | if (ctx->state == ASN1_STATE_POST_COPY) | 428 | if (ctx->state == ASN1_STATE_POST_COPY) |
429 | { | 429 | { |
430 | ret = asn1_bio_flush_ex(b, ctx, ctx->suffix_free, | 430 | ret = asn1_bio_flush_ex(b, ctx, ctx->suffix_free, |
431 | ASN1_STATE_DONE); | 431 | ASN1_STATE_DONE); |
432 | if (ret <= 0) | 432 | if (ret <= 0) |
433 | return ret; | 433 | return ret; |
434 | } | 434 | } |
435 | 435 | ||
436 | if (ctx->state == ASN1_STATE_DONE) | 436 | if (ctx->state == ASN1_STATE_DONE) |
437 | return BIO_ctrl(b->next_bio, cmd, arg1, arg2); | 437 | return BIO_ctrl(b->next_bio, cmd, arg1, arg2); |
438 | else | 438 | else |
439 | { | 439 | { |
440 | BIO_clear_retry_flags(b); | 440 | BIO_clear_retry_flags(b); |
441 | return 0; | 441 | return 0; |
442 | } | 442 | } |
443 | break; | 443 | break; |
444 | 444 | ||
445 | 445 | ||
@@ -448,50 +448,50 @@ static long asn1_bio_ctrl(BIO *b, int cmd, long arg1, void *arg2) | |||
448 | return 0; | 448 | return 0; |
449 | return BIO_ctrl(b->next_bio, cmd, arg1, arg2); | 449 | return BIO_ctrl(b->next_bio, cmd, arg1, arg2); |
450 | 450 | ||
451 | } | 451 | } |
452 | 452 | ||
453 | return ret; | 453 | return ret; |
454 | } | 454 | } |
455 | 455 | ||
456 | static int asn1_bio_set_ex(BIO *b, int cmd, | 456 | static int asn1_bio_set_ex(BIO *b, int cmd, |
457 | asn1_ps_func *ex_func, asn1_ps_func *ex_free_func) | 457 | asn1_ps_func *ex_func, asn1_ps_func *ex_free_func) |
458 | { | 458 | { |
459 | BIO_ASN1_EX_FUNCS extmp; | 459 | BIO_ASN1_EX_FUNCS extmp; |
460 | extmp.ex_func = ex_func; | 460 | extmp.ex_func = ex_func; |
461 | extmp.ex_free_func = ex_free_func; | 461 | extmp.ex_free_func = ex_free_func; |
462 | return BIO_ctrl(b, cmd, 0, &extmp); | 462 | return BIO_ctrl(b, cmd, 0, &extmp); |
463 | } | 463 | } |
464 | 464 | ||
465 | static int asn1_bio_get_ex(BIO *b, int cmd, | 465 | static int asn1_bio_get_ex(BIO *b, int cmd, |
466 | asn1_ps_func **ex_func, asn1_ps_func **ex_free_func) | 466 | asn1_ps_func **ex_func, asn1_ps_func **ex_free_func) |
467 | { | 467 | { |
468 | BIO_ASN1_EX_FUNCS extmp; | 468 | BIO_ASN1_EX_FUNCS extmp; |
469 | int ret; | 469 | int ret; |
470 | ret = BIO_ctrl(b, cmd, 0, &extmp); | 470 | ret = BIO_ctrl(b, cmd, 0, &extmp); |
471 | if (ret > 0) | 471 | if (ret > 0) |
472 | { | 472 | { |
473 | *ex_func = extmp.ex_func; | 473 | *ex_func = extmp.ex_func; |
474 | *ex_free_func = extmp.ex_free_func; | 474 | *ex_free_func = extmp.ex_free_func; |
475 | } | ||
476 | return ret; | ||
477 | } | 475 | } |
476 | return ret; | ||
477 | } | ||
478 | 478 | ||
479 | int BIO_asn1_set_prefix(BIO *b, asn1_ps_func *prefix, asn1_ps_func *prefix_free) | 479 | int BIO_asn1_set_prefix(BIO *b, asn1_ps_func *prefix, asn1_ps_func *prefix_free) |
480 | { | 480 | { |
481 | return asn1_bio_set_ex(b, BIO_C_SET_PREFIX, prefix, prefix_free); | 481 | return asn1_bio_set_ex(b, BIO_C_SET_PREFIX, prefix, prefix_free); |
482 | } | 482 | } |
483 | 483 | ||
484 | int BIO_asn1_get_prefix(BIO *b, asn1_ps_func **pprefix, asn1_ps_func **pprefix_free) | 484 | int BIO_asn1_get_prefix(BIO *b, asn1_ps_func **pprefix, asn1_ps_func **pprefix_free) |
485 | { | 485 | { |
486 | return asn1_bio_get_ex(b, BIO_C_GET_PREFIX, pprefix, pprefix_free); | 486 | return asn1_bio_get_ex(b, BIO_C_GET_PREFIX, pprefix, pprefix_free); |
487 | } | 487 | } |
488 | 488 | ||
489 | int BIO_asn1_set_suffix(BIO *b, asn1_ps_func *suffix, asn1_ps_func *suffix_free) | 489 | int BIO_asn1_set_suffix(BIO *b, asn1_ps_func *suffix, asn1_ps_func *suffix_free) |
490 | { | 490 | { |
491 | return asn1_bio_set_ex(b, BIO_C_SET_SUFFIX, suffix, suffix_free); | 491 | return asn1_bio_set_ex(b, BIO_C_SET_SUFFIX, suffix, suffix_free); |
492 | } | 492 | } |
493 | 493 | ||
494 | int BIO_asn1_get_suffix(BIO *b, asn1_ps_func **psuffix, asn1_ps_func **psuffix_free) | 494 | int BIO_asn1_get_suffix(BIO *b, asn1_ps_func **psuffix, asn1_ps_func **psuffix_free) |
495 | { | 495 | { |
496 | return asn1_bio_get_ex(b, BIO_C_GET_SUFFIX, psuffix, psuffix_free); | 496 | return asn1_bio_get_ex(b, BIO_C_GET_SUFFIX, psuffix, psuffix_free); |
497 | } | 497 | } |
diff --git a/src/lib/libssl/src/crypto/asn1/bio_ndef.c b/src/lib/libssl/src/crypto/asn1/bio_ndef.c index 60f324bdae..b8dc80a7b2 100644 --- a/src/lib/libssl/src/crypto/asn1/bio_ndef.c +++ b/src/lib/libssl/src/crypto/asn1/bio_ndef.c | |||
@@ -79,7 +79,7 @@ | |||
79 | /* BIO support data stored in the ASN1 BIO ex_arg */ | 79 | /* BIO support data stored in the ASN1 BIO ex_arg */ |
80 | 80 | ||
81 | typedef struct ndef_aux_st | 81 | typedef struct ndef_aux_st |
82 | { | 82 | { |
83 | /* ASN1 structure this BIO refers to */ | 83 | /* ASN1 structure this BIO refers to */ |
84 | ASN1_VALUE *val; | 84 | ASN1_VALUE *val; |
85 | const ASN1_ITEM *it; | 85 | const ASN1_ITEM *it; |
@@ -91,7 +91,7 @@ typedef struct ndef_aux_st | |||
91 | unsigned char **boundary; | 91 | unsigned char **boundary; |
92 | /* DER buffer start */ | 92 | /* DER buffer start */ |
93 | unsigned char *derbuf; | 93 | unsigned char *derbuf; |
94 | } NDEF_SUPPORT; | 94 | } NDEF_SUPPORT; |
95 | 95 | ||
96 | static int ndef_prefix(BIO *b, unsigned char **pbuf, int *plen, void *parg); | 96 | static int ndef_prefix(BIO *b, unsigned char **pbuf, int *plen, void *parg); |
97 | static int ndef_prefix_free(BIO *b, unsigned char **pbuf, int *plen, void *parg); | 97 | static int ndef_prefix_free(BIO *b, unsigned char **pbuf, int *plen, void *parg); |
@@ -99,17 +99,17 @@ static int ndef_suffix(BIO *b, unsigned char **pbuf, int *plen, void *parg); | |||
99 | static int ndef_suffix_free(BIO *b, unsigned char **pbuf, int *plen, void *parg); | 99 | static int ndef_suffix_free(BIO *b, unsigned char **pbuf, int *plen, void *parg); |
100 | 100 | ||
101 | BIO *BIO_new_NDEF(BIO *out, ASN1_VALUE *val, const ASN1_ITEM *it) | 101 | BIO *BIO_new_NDEF(BIO *out, ASN1_VALUE *val, const ASN1_ITEM *it) |
102 | { | 102 | { |
103 | NDEF_SUPPORT *ndef_aux = NULL; | 103 | NDEF_SUPPORT *ndef_aux = NULL; |
104 | BIO *asn_bio = NULL; | 104 | BIO *asn_bio = NULL; |
105 | const ASN1_AUX *aux = it->funcs; | 105 | const ASN1_AUX *aux = it->funcs; |
106 | ASN1_STREAM_ARG sarg; | 106 | ASN1_STREAM_ARG sarg; |
107 | 107 | ||
108 | if (!aux || !aux->asn1_cb) | 108 | if (!aux || !aux->asn1_cb) |
109 | { | 109 | { |
110 | ASN1err(ASN1_F_BIO_NEW_NDEF, ASN1_R_STREAMING_NOT_SUPPORTED); | 110 | ASN1err(ASN1_F_BIO_NEW_NDEF, ASN1_R_STREAMING_NOT_SUPPORTED); |
111 | return NULL; | 111 | return NULL; |
112 | } | 112 | } |
113 | ndef_aux = malloc(sizeof(NDEF_SUPPORT)); | 113 | ndef_aux = malloc(sizeof(NDEF_SUPPORT)); |
114 | asn_bio = BIO_new(BIO_f_asn1()); | 114 | asn_bio = BIO_new(BIO_f_asn1()); |
115 | 115 | ||
@@ -150,10 +150,10 @@ BIO *BIO_new_NDEF(BIO *out, ASN1_VALUE *val, const ASN1_ITEM *it) | |||
150 | if (ndef_aux) | 150 | if (ndef_aux) |
151 | free(ndef_aux); | 151 | free(ndef_aux); |
152 | return NULL; | 152 | return NULL; |
153 | } | 153 | } |
154 | 154 | ||
155 | static int ndef_prefix(BIO *b, unsigned char **pbuf, int *plen, void *parg) | 155 | static int ndef_prefix(BIO *b, unsigned char **pbuf, int *plen, void *parg) |
156 | { | 156 | { |
157 | NDEF_SUPPORT *ndef_aux; | 157 | NDEF_SUPPORT *ndef_aux; |
158 | unsigned char *p; | 158 | unsigned char *p; |
159 | int derlen; | 159 | int derlen; |
@@ -175,10 +175,10 @@ static int ndef_prefix(BIO *b, unsigned char **pbuf, int *plen, void *parg) | |||
175 | *plen = *ndef_aux->boundary - *pbuf; | 175 | *plen = *ndef_aux->boundary - *pbuf; |
176 | 176 | ||
177 | return 1; | 177 | return 1; |
178 | } | 178 | } |
179 | 179 | ||
180 | static int ndef_prefix_free(BIO *b, unsigned char **pbuf, int *plen, void *parg) | 180 | static int ndef_prefix_free(BIO *b, unsigned char **pbuf, int *plen, void *parg) |
181 | { | 181 | { |
182 | NDEF_SUPPORT *ndef_aux; | 182 | NDEF_SUPPORT *ndef_aux; |
183 | 183 | ||
184 | if (!parg) | 184 | if (!parg) |
@@ -193,20 +193,20 @@ static int ndef_prefix_free(BIO *b, unsigned char **pbuf, int *plen, void *parg) | |||
193 | *pbuf = NULL; | 193 | *pbuf = NULL; |
194 | *plen = 0; | 194 | *plen = 0; |
195 | return 1; | 195 | return 1; |
196 | } | 196 | } |
197 | 197 | ||
198 | static int ndef_suffix_free(BIO *b, unsigned char **pbuf, int *plen, void *parg) | 198 | static int ndef_suffix_free(BIO *b, unsigned char **pbuf, int *plen, void *parg) |
199 | { | 199 | { |
200 | NDEF_SUPPORT **pndef_aux = (NDEF_SUPPORT **)parg; | 200 | NDEF_SUPPORT **pndef_aux = (NDEF_SUPPORT **)parg; |
201 | if (!ndef_prefix_free(b, pbuf, plen, parg)) | 201 | if (!ndef_prefix_free(b, pbuf, plen, parg)) |
202 | return 0; | 202 | return 0; |
203 | free(*pndef_aux); | 203 | free(*pndef_aux); |
204 | *pndef_aux = NULL; | 204 | *pndef_aux = NULL; |
205 | return 1; | 205 | return 1; |
206 | } | 206 | } |
207 | 207 | ||
208 | static int ndef_suffix(BIO *b, unsigned char **pbuf, int *plen, void *parg) | 208 | static int ndef_suffix(BIO *b, unsigned char **pbuf, int *plen, void *parg) |
209 | { | 209 | { |
210 | NDEF_SUPPORT *ndef_aux; | 210 | NDEF_SUPPORT *ndef_aux; |
211 | unsigned char *p; | 211 | unsigned char *p; |
212 | int derlen; | 212 | int derlen; |
@@ -240,4 +240,4 @@ static int ndef_suffix(BIO *b, unsigned char **pbuf, int *plen, void *parg) | |||
240 | *plen = derlen - (*ndef_aux->boundary - ndef_aux->derbuf); | 240 | *plen = derlen - (*ndef_aux->boundary - ndef_aux->derbuf); |
241 | 241 | ||
242 | return 1; | 242 | return 1; |
243 | } | 243 | } |
diff --git a/src/lib/libssl/src/crypto/asn1/d2i_pr.c b/src/lib/libssl/src/crypto/asn1/d2i_pr.c index 2828944777..cbbcdae7df 100644 --- a/src/lib/libssl/src/crypto/asn1/d2i_pr.c +++ b/src/lib/libssl/src/crypto/asn1/d2i_pr.c | |||
@@ -70,40 +70,40 @@ | |||
70 | 70 | ||
71 | EVP_PKEY *d2i_PrivateKey(int type, EVP_PKEY **a, const unsigned char **pp, | 71 | EVP_PKEY *d2i_PrivateKey(int type, EVP_PKEY **a, const unsigned char **pp, |
72 | long length) | 72 | long length) |
73 | { | 73 | { |
74 | EVP_PKEY *ret; | 74 | EVP_PKEY *ret; |
75 | 75 | ||
76 | if ((a == NULL) || (*a == NULL)) | 76 | if ((a == NULL) || (*a == NULL)) |
77 | { | 77 | { |
78 | if ((ret=EVP_PKEY_new()) == NULL) | 78 | if ((ret=EVP_PKEY_new()) == NULL) |
79 | { | 79 | { |
80 | ASN1err(ASN1_F_D2I_PRIVATEKEY,ERR_R_EVP_LIB); | 80 | ASN1err(ASN1_F_D2I_PRIVATEKEY,ERR_R_EVP_LIB); |
81 | return(NULL); | 81 | return(NULL); |
82 | } | ||
83 | } | 82 | } |
83 | } | ||
84 | else | 84 | else |
85 | { | 85 | { |
86 | ret= *a; | 86 | ret= *a; |
87 | #ifndef OPENSSL_NO_ENGINE | 87 | #ifndef OPENSSL_NO_ENGINE |
88 | if (ret->engine) | 88 | if (ret->engine) |
89 | { | 89 | { |
90 | ENGINE_finish(ret->engine); | 90 | ENGINE_finish(ret->engine); |
91 | ret->engine = NULL; | 91 | ret->engine = NULL; |
92 | } | ||
93 | #endif | ||
94 | } | 92 | } |
93 | #endif | ||
94 | } | ||
95 | 95 | ||
96 | if (!EVP_PKEY_set_type(ret, type)) | 96 | if (!EVP_PKEY_set_type(ret, type)) |
97 | { | 97 | { |
98 | ASN1err(ASN1_F_D2I_PRIVATEKEY,ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE); | 98 | ASN1err(ASN1_F_D2I_PRIVATEKEY,ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE); |
99 | goto err; | 99 | goto err; |
100 | } | 100 | } |
101 | 101 | ||
102 | if (!ret->ameth->old_priv_decode || | 102 | if (!ret->ameth->old_priv_decode || |
103 | !ret->ameth->old_priv_decode(ret, pp, length)) | 103 | !ret->ameth->old_priv_decode(ret, pp, length)) |
104 | { | 104 | { |
105 | if (ret->ameth->priv_decode) | 105 | if (ret->ameth->priv_decode) |
106 | { | 106 | { |
107 | PKCS8_PRIV_KEY_INFO *p8=NULL; | 107 | PKCS8_PRIV_KEY_INFO *p8=NULL; |
108 | p8=d2i_PKCS8_PRIV_KEY_INFO(NULL,pp,length); | 108 | p8=d2i_PKCS8_PRIV_KEY_INFO(NULL,pp,length); |
109 | if (!p8) goto err; | 109 | if (!p8) goto err; |
@@ -111,19 +111,19 @@ EVP_PKEY *d2i_PrivateKey(int type, EVP_PKEY **a, const unsigned char **pp, | |||
111 | ret = EVP_PKCS82PKEY(p8); | 111 | ret = EVP_PKCS82PKEY(p8); |
112 | PKCS8_PRIV_KEY_INFO_free(p8); | 112 | PKCS8_PRIV_KEY_INFO_free(p8); |
113 | 113 | ||
114 | } | 114 | } |
115 | else | 115 | else |
116 | { | 116 | { |
117 | ASN1err(ASN1_F_D2I_PRIVATEKEY,ERR_R_ASN1_LIB); | 117 | ASN1err(ASN1_F_D2I_PRIVATEKEY,ERR_R_ASN1_LIB); |
118 | goto err; | 118 | goto err; |
119 | } | 119 | } |
120 | } | 120 | } |
121 | if (a != NULL) (*a)=ret; | 121 | if (a != NULL) (*a)=ret; |
122 | return(ret); | 122 | return(ret); |
123 | err: | 123 | err: |
124 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) EVP_PKEY_free(ret); | 124 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) EVP_PKEY_free(ret); |
125 | return(NULL); | 125 | return(NULL); |
126 | } | 126 | } |
127 | 127 | ||
128 | /* This works like d2i_PrivateKey() except it automatically works out the type */ | 128 | /* This works like d2i_PrivateKey() except it automatically works out the type */ |
129 | 129 | ||
@@ -147,23 +147,23 @@ EVP_PKEY *d2i_AutoPrivateKey(EVP_PKEY **a, const unsigned char **pp, | |||
147 | else if (sk_ASN1_TYPE_num(inkey) == 4) | 147 | else if (sk_ASN1_TYPE_num(inkey) == 4) |
148 | keytype = EVP_PKEY_EC; | 148 | keytype = EVP_PKEY_EC; |
149 | else if (sk_ASN1_TYPE_num(inkey) == 3) | 149 | else if (sk_ASN1_TYPE_num(inkey) == 3) |
150 | { /* This seems to be PKCS8, not traditional format */ | 150 | { /* This seems to be PKCS8, not traditional format */ |
151 | PKCS8_PRIV_KEY_INFO *p8 = d2i_PKCS8_PRIV_KEY_INFO(NULL,pp,length); | 151 | PKCS8_PRIV_KEY_INFO *p8 = d2i_PKCS8_PRIV_KEY_INFO(NULL,pp,length); |
152 | EVP_PKEY *ret; | 152 | EVP_PKEY *ret; |
153 | 153 | ||
154 | sk_ASN1_TYPE_pop_free(inkey, ASN1_TYPE_free); | 154 | sk_ASN1_TYPE_pop_free(inkey, ASN1_TYPE_free); |
155 | if (!p8) | 155 | if (!p8) |
156 | { | 156 | { |
157 | ASN1err(ASN1_F_D2I_AUTOPRIVATEKEY,ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE); | 157 | ASN1err(ASN1_F_D2I_AUTOPRIVATEKEY,ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE); |
158 | return NULL; | 158 | return NULL; |
159 | } | 159 | } |
160 | ret = EVP_PKCS82PKEY(p8); | 160 | ret = EVP_PKCS82PKEY(p8); |
161 | PKCS8_PRIV_KEY_INFO_free(p8); | 161 | PKCS8_PRIV_KEY_INFO_free(p8); |
162 | if (a) { | 162 | if (a) { |
163 | *a = ret; | 163 | *a = ret; |
164 | } | 164 | } |
165 | return ret; | 165 | return ret; |
166 | } | 166 | } |
167 | else keytype = EVP_PKEY_RSA; | 167 | else keytype = EVP_PKEY_RSA; |
168 | sk_ASN1_TYPE_pop_free(inkey, ASN1_TYPE_free); | 168 | sk_ASN1_TYPE_pop_free(inkey, ASN1_TYPE_free); |
169 | return d2i_PrivateKey(keytype, a, pp, length); | 169 | return d2i_PrivateKey(keytype, a, pp, length); |
diff --git a/src/lib/libssl/src/crypto/asn1/d2i_pu.c b/src/lib/libssl/src/crypto/asn1/d2i_pu.c index c8f39ceb03..f04d230d70 100644 --- a/src/lib/libssl/src/crypto/asn1/d2i_pu.c +++ b/src/lib/libssl/src/crypto/asn1/d2i_pu.c | |||
@@ -74,66 +74,66 @@ | |||
74 | 74 | ||
75 | EVP_PKEY *d2i_PublicKey(int type, EVP_PKEY **a, const unsigned char **pp, | 75 | EVP_PKEY *d2i_PublicKey(int type, EVP_PKEY **a, const unsigned char **pp, |
76 | long length) | 76 | long length) |
77 | { | 77 | { |
78 | EVP_PKEY *ret; | 78 | EVP_PKEY *ret; |
79 | 79 | ||
80 | if ((a == NULL) || (*a == NULL)) | 80 | if ((a == NULL) || (*a == NULL)) |
81 | { | 81 | { |
82 | if ((ret=EVP_PKEY_new()) == NULL) | 82 | if ((ret=EVP_PKEY_new()) == NULL) |
83 | { | 83 | { |
84 | ASN1err(ASN1_F_D2I_PUBLICKEY,ERR_R_EVP_LIB); | 84 | ASN1err(ASN1_F_D2I_PUBLICKEY,ERR_R_EVP_LIB); |
85 | return(NULL); | 85 | return(NULL); |
86 | } | ||
87 | } | 86 | } |
87 | } | ||
88 | else ret= *a; | 88 | else ret= *a; |
89 | 89 | ||
90 | if (!EVP_PKEY_set_type(ret, type)) | 90 | if (!EVP_PKEY_set_type(ret, type)) |
91 | { | 91 | { |
92 | ASN1err(ASN1_F_D2I_PUBLICKEY,ERR_R_EVP_LIB); | 92 | ASN1err(ASN1_F_D2I_PUBLICKEY,ERR_R_EVP_LIB); |
93 | goto err; | 93 | goto err; |
94 | } | 94 | } |
95 | 95 | ||
96 | switch (EVP_PKEY_id(ret)) | 96 | switch (EVP_PKEY_id(ret)) |
97 | { | 97 | { |
98 | #ifndef OPENSSL_NO_RSA | 98 | #ifndef OPENSSL_NO_RSA |
99 | case EVP_PKEY_RSA: | 99 | case EVP_PKEY_RSA: |
100 | if ((ret->pkey.rsa=d2i_RSAPublicKey(NULL, | 100 | if ((ret->pkey.rsa=d2i_RSAPublicKey(NULL, |
101 | (const unsigned char **)pp,length)) == NULL) /* TMP UGLY CAST */ | 101 | (const unsigned char **)pp,length)) == NULL) /* TMP UGLY CAST */ |
102 | { | 102 | { |
103 | ASN1err(ASN1_F_D2I_PUBLICKEY,ERR_R_ASN1_LIB); | 103 | ASN1err(ASN1_F_D2I_PUBLICKEY,ERR_R_ASN1_LIB); |
104 | goto err; | 104 | goto err; |
105 | } | 105 | } |
106 | break; | 106 | break; |
107 | #endif | 107 | #endif |
108 | #ifndef OPENSSL_NO_DSA | 108 | #ifndef OPENSSL_NO_DSA |
109 | case EVP_PKEY_DSA: | 109 | case EVP_PKEY_DSA: |
110 | if (!d2i_DSAPublicKey(&(ret->pkey.dsa), | 110 | if (!d2i_DSAPublicKey(&(ret->pkey.dsa), |
111 | (const unsigned char **)pp,length)) /* TMP UGLY CAST */ | 111 | (const unsigned char **)pp,length)) /* TMP UGLY CAST */ |
112 | { | 112 | { |
113 | ASN1err(ASN1_F_D2I_PUBLICKEY,ERR_R_ASN1_LIB); | 113 | ASN1err(ASN1_F_D2I_PUBLICKEY,ERR_R_ASN1_LIB); |
114 | goto err; | 114 | goto err; |
115 | } | 115 | } |
116 | break; | 116 | break; |
117 | #endif | 117 | #endif |
118 | #ifndef OPENSSL_NO_EC | 118 | #ifndef OPENSSL_NO_EC |
119 | case EVP_PKEY_EC: | 119 | case EVP_PKEY_EC: |
120 | if (!o2i_ECPublicKey(&(ret->pkey.ec), | 120 | if (!o2i_ECPublicKey(&(ret->pkey.ec), |
121 | (const unsigned char **)pp, length)) | 121 | (const unsigned char **)pp, length)) |
122 | { | 122 | { |
123 | ASN1err(ASN1_F_D2I_PUBLICKEY, ERR_R_ASN1_LIB); | 123 | ASN1err(ASN1_F_D2I_PUBLICKEY, ERR_R_ASN1_LIB); |
124 | goto err; | 124 | goto err; |
125 | } | 125 | } |
126 | break; | 126 | break; |
127 | #endif | 127 | #endif |
128 | default: | 128 | default: |
129 | ASN1err(ASN1_F_D2I_PUBLICKEY,ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE); | 129 | ASN1err(ASN1_F_D2I_PUBLICKEY,ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE); |
130 | goto err; | 130 | goto err; |
131 | /* break; */ | 131 | /* break; */ |
132 | } | 132 | } |
133 | if (a != NULL) (*a)=ret; | 133 | if (a != NULL) (*a)=ret; |
134 | return(ret); | 134 | return(ret); |
135 | err: | 135 | err: |
136 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) EVP_PKEY_free(ret); | 136 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) EVP_PKEY_free(ret); |
137 | return(NULL); | 137 | return(NULL); |
138 | } | 138 | } |
139 | 139 | ||
diff --git a/src/lib/libssl/src/crypto/asn1/evp_asn1.c b/src/lib/libssl/src/crypto/asn1/evp_asn1.c index f3d9804860..631924f88e 100644 --- a/src/lib/libssl/src/crypto/asn1/evp_asn1.c +++ b/src/lib/libssl/src/crypto/asn1/evp_asn1.c | |||
@@ -62,27 +62,27 @@ | |||
62 | #include <openssl/asn1_mac.h> | 62 | #include <openssl/asn1_mac.h> |
63 | 63 | ||
64 | int ASN1_TYPE_set_octetstring(ASN1_TYPE *a, unsigned char *data, int len) | 64 | int ASN1_TYPE_set_octetstring(ASN1_TYPE *a, unsigned char *data, int len) |
65 | { | 65 | { |
66 | ASN1_STRING *os; | 66 | ASN1_STRING *os; |
67 | 67 | ||
68 | if ((os=M_ASN1_OCTET_STRING_new()) == NULL) return(0); | 68 | if ((os=M_ASN1_OCTET_STRING_new()) == NULL) return(0); |
69 | if (!M_ASN1_OCTET_STRING_set(os,data,len)) return(0); | 69 | if (!M_ASN1_OCTET_STRING_set(os,data,len)) return(0); |
70 | ASN1_TYPE_set(a,V_ASN1_OCTET_STRING,os); | 70 | ASN1_TYPE_set(a,V_ASN1_OCTET_STRING,os); |
71 | return(1); | 71 | return(1); |
72 | } | 72 | } |
73 | 73 | ||
74 | /* int max_len: for returned value */ | 74 | /* int max_len: for returned value */ |
75 | int ASN1_TYPE_get_octetstring(ASN1_TYPE *a, unsigned char *data, | 75 | int ASN1_TYPE_get_octetstring(ASN1_TYPE *a, unsigned char *data, |
76 | int max_len) | 76 | int max_len) |
77 | { | 77 | { |
78 | int ret,num; | 78 | int ret,num; |
79 | unsigned char *p; | 79 | unsigned char *p; |
80 | 80 | ||
81 | if ((a->type != V_ASN1_OCTET_STRING) || (a->value.octet_string == NULL)) | 81 | if ((a->type != V_ASN1_OCTET_STRING) || (a->value.octet_string == NULL)) |
82 | { | 82 | { |
83 | ASN1err(ASN1_F_ASN1_TYPE_GET_OCTETSTRING,ASN1_R_DATA_IS_WRONG); | 83 | ASN1err(ASN1_F_ASN1_TYPE_GET_OCTETSTRING,ASN1_R_DATA_IS_WRONG); |
84 | return(-1); | 84 | return(-1); |
85 | } | 85 | } |
86 | p=M_ASN1_STRING_data(a->value.octet_string); | 86 | p=M_ASN1_STRING_data(a->value.octet_string); |
87 | ret=M_ASN1_STRING_length(a->value.octet_string); | 87 | ret=M_ASN1_STRING_length(a->value.octet_string); |
88 | if (ret < max_len) | 88 | if (ret < max_len) |
@@ -91,11 +91,11 @@ int ASN1_TYPE_get_octetstring(ASN1_TYPE *a, unsigned char *data, | |||
91 | num=max_len; | 91 | num=max_len; |
92 | memcpy(data,p,num); | 92 | memcpy(data,p,num); |
93 | return(ret); | 93 | return(ret); |
94 | } | 94 | } |
95 | 95 | ||
96 | int ASN1_TYPE_set_int_octetstring(ASN1_TYPE *a, long num, unsigned char *data, | 96 | int ASN1_TYPE_set_int_octetstring(ASN1_TYPE *a, long num, unsigned char *data, |
97 | int len) | 97 | int len) |
98 | { | 98 | { |
99 | int n,size; | 99 | int n,size; |
100 | ASN1_OCTET_STRING os,*osp; | 100 | ASN1_OCTET_STRING os,*osp; |
101 | ASN1_INTEGER in; | 101 | ASN1_INTEGER in; |
@@ -116,10 +116,10 @@ int ASN1_TYPE_set_int_octetstring(ASN1_TYPE *a, long num, unsigned char *data, | |||
116 | if ((osp=ASN1_STRING_new()) == NULL) return(0); | 116 | if ((osp=ASN1_STRING_new()) == NULL) return(0); |
117 | /* Grow the 'string' */ | 117 | /* Grow the 'string' */ |
118 | if (!ASN1_STRING_set(osp,NULL,size)) | 118 | if (!ASN1_STRING_set(osp,NULL,size)) |
119 | { | 119 | { |
120 | ASN1_STRING_free(osp); | 120 | ASN1_STRING_free(osp); |
121 | return(0); | 121 | return(0); |
122 | } | 122 | } |
123 | 123 | ||
124 | M_ASN1_STRING_length_set(osp, size); | 124 | M_ASN1_STRING_length_set(osp, size); |
125 | p=M_ASN1_STRING_data(osp); | 125 | p=M_ASN1_STRING_data(osp); |
@@ -130,14 +130,14 @@ int ASN1_TYPE_set_int_octetstring(ASN1_TYPE *a, long num, unsigned char *data, | |||
130 | 130 | ||
131 | ASN1_TYPE_set(a,V_ASN1_SEQUENCE,osp); | 131 | ASN1_TYPE_set(a,V_ASN1_SEQUENCE,osp); |
132 | return(1); | 132 | return(1); |
133 | } | 133 | } |
134 | 134 | ||
135 | /* we return the actual length..., num may be missing, in which | 135 | /* we return the actual length..., num may be missing, in which |
136 | * case, set it to zero */ | 136 | * case, set it to zero */ |
137 | /* int max_len: for returned value */ | 137 | /* int max_len: for returned value */ |
138 | int ASN1_TYPE_get_int_octetstring(ASN1_TYPE *a, long *num, unsigned char *data, | 138 | int ASN1_TYPE_get_int_octetstring(ASN1_TYPE *a, long *num, unsigned char *data, |
139 | int max_len) | 139 | int max_len) |
140 | { | 140 | { |
141 | int ret= -1,n; | 141 | int ret= -1,n; |
142 | ASN1_INTEGER *ai=NULL; | 142 | ASN1_INTEGER *ai=NULL; |
143 | ASN1_OCTET_STRING *os=NULL; | 143 | ASN1_OCTET_STRING *os=NULL; |
@@ -146,9 +146,9 @@ int ASN1_TYPE_get_int_octetstring(ASN1_TYPE *a, long *num, unsigned char *data, | |||
146 | ASN1_const_CTX c; | 146 | ASN1_const_CTX c; |
147 | 147 | ||
148 | if ((a->type != V_ASN1_SEQUENCE) || (a->value.sequence == NULL)) | 148 | if ((a->type != V_ASN1_SEQUENCE) || (a->value.sequence == NULL)) |
149 | { | 149 | { |
150 | goto err; | 150 | goto err; |
151 | } | 151 | } |
152 | p=M_ASN1_STRING_data(a->value.sequence); | 152 | p=M_ASN1_STRING_data(a->value.sequence); |
153 | length=M_ASN1_STRING_length(a->value.sequence); | 153 | length=M_ASN1_STRING_length(a->value.sequence); |
154 | 154 | ||
@@ -178,12 +178,12 @@ int ASN1_TYPE_get_int_octetstring(ASN1_TYPE *a, long *num, unsigned char *data, | |||
178 | if (data != NULL) | 178 | if (data != NULL) |
179 | memcpy(data,M_ASN1_STRING_data(os),n); | 179 | memcpy(data,M_ASN1_STRING_data(os),n); |
180 | if (0) | 180 | if (0) |
181 | { | 181 | { |
182 | err: | 182 | err: |
183 | ASN1err(ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING,ASN1_R_DATA_IS_WRONG); | 183 | ASN1err(ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING,ASN1_R_DATA_IS_WRONG); |
184 | } | 184 | } |
185 | if (os != NULL) M_ASN1_OCTET_STRING_free(os); | 185 | if (os != NULL) M_ASN1_OCTET_STRING_free(os); |
186 | if (ai != NULL) M_ASN1_INTEGER_free(ai); | 186 | if (ai != NULL) M_ASN1_INTEGER_free(ai); |
187 | return(ret); | 187 | return(ret); |
188 | } | 188 | } |
189 | 189 | ||
diff --git a/src/lib/libssl/src/crypto/asn1/f_enum.c b/src/lib/libssl/src/crypto/asn1/f_enum.c index caf34ee97e..b6e66ab194 100644 --- a/src/lib/libssl/src/crypto/asn1/f_enum.c +++ b/src/lib/libssl/src/crypto/asn1/f_enum.c | |||
@@ -64,7 +64,7 @@ | |||
64 | /* Based on a_int.c: equivalent ENUMERATED functions */ | 64 | /* Based on a_int.c: equivalent ENUMERATED functions */ |
65 | 65 | ||
66 | int i2a_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *a) | 66 | int i2a_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *a) |
67 | { | 67 | { |
68 | int i,n=0; | 68 | int i,n=0; |
69 | static const char *h="0123456789ABCDEF"; | 69 | static const char *h="0123456789ABCDEF"; |
70 | char buf[2]; | 70 | char buf[2]; |
@@ -72,32 +72,32 @@ int i2a_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *a) | |||
72 | if (a == NULL) return(0); | 72 | if (a == NULL) return(0); |
73 | 73 | ||
74 | if (a->length == 0) | 74 | if (a->length == 0) |
75 | { | 75 | { |
76 | if (BIO_write(bp,"00",2) != 2) goto err; | 76 | if (BIO_write(bp,"00",2) != 2) goto err; |
77 | n=2; | 77 | n=2; |
78 | } | 78 | } |
79 | else | 79 | else |
80 | { | 80 | { |
81 | for (i=0; i<a->length; i++) | 81 | for (i=0; i<a->length; i++) |
82 | { | 82 | { |
83 | if ((i != 0) && (i%35 == 0)) | 83 | if ((i != 0) && (i%35 == 0)) |
84 | { | 84 | { |
85 | if (BIO_write(bp,"\\\n",2) != 2) goto err; | 85 | if (BIO_write(bp,"\\\n",2) != 2) goto err; |
86 | n+=2; | 86 | n+=2; |
87 | } | 87 | } |
88 | buf[0]=h[((unsigned char)a->data[i]>>4)&0x0f]; | 88 | buf[0]=h[((unsigned char)a->data[i]>>4)&0x0f]; |
89 | buf[1]=h[((unsigned char)a->data[i] )&0x0f]; | 89 | buf[1]=h[((unsigned char)a->data[i] )&0x0f]; |
90 | if (BIO_write(bp,buf,2) != 2) goto err; | 90 | if (BIO_write(bp,buf,2) != 2) goto err; |
91 | n+=2; | 91 | n+=2; |
92 | } | ||
93 | } | 92 | } |
93 | } | ||
94 | return(n); | 94 | return(n); |
95 | err: | 95 | err: |
96 | return(-1); | 96 | return(-1); |
97 | } | 97 | } |
98 | 98 | ||
99 | int a2i_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *bs, char *buf, int size) | 99 | int a2i_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *bs, char *buf, int size) |
100 | { | 100 | { |
101 | int ret=0; | 101 | int ret=0; |
102 | int i,j,k,m,n,again,bufsize; | 102 | int i,j,k,m,n,again,bufsize; |
103 | unsigned char *s=NULL,*sp; | 103 | unsigned char *s=NULL,*sp; |
@@ -108,7 +108,7 @@ int a2i_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *bs, char *buf, int size) | |||
108 | 108 | ||
109 | bufsize=BIO_gets(bp,buf,size); | 109 | bufsize=BIO_gets(bp,buf,size); |
110 | for (;;) | 110 | for (;;) |
111 | { | 111 | { |
112 | if (bufsize < 1) goto err_sl; | 112 | if (bufsize < 1) goto err_sl; |
113 | i=bufsize; | 113 | i=bufsize; |
114 | if (buf[i-1] == '\n') buf[--i]='\0'; | 114 | if (buf[i-1] == '\n') buf[--i]='\0'; |
@@ -118,15 +118,15 @@ int a2i_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *bs, char *buf, int size) | |||
118 | again=(buf[i-1] == '\\'); | 118 | again=(buf[i-1] == '\\'); |
119 | 119 | ||
120 | for (j=0; j<i; j++) | 120 | for (j=0; j<i; j++) |
121 | { | 121 | { |
122 | if (!( ((buf[j] >= '0') && (buf[j] <= '9')) || | 122 | if (!( ((buf[j] >= '0') && (buf[j] <= '9')) || |
123 | ((buf[j] >= 'a') && (buf[j] <= 'f')) || | 123 | ((buf[j] >= 'a') && (buf[j] <= 'f')) || |
124 | ((buf[j] >= 'A') && (buf[j] <= 'F')))) | 124 | ((buf[j] >= 'A') && (buf[j] <= 'F')))) |
125 | { | 125 | { |
126 | i=j; | 126 | i=j; |
127 | break; | 127 | break; |
128 | } | ||
129 | } | 128 | } |
129 | } | ||
130 | buf[i]='\0'; | 130 | buf[i]='\0'; |
131 | /* We have now cleared all the crap off the end of the | 131 | /* We have now cleared all the crap off the end of the |
132 | * line */ | 132 | * line */ |
@@ -134,24 +134,24 @@ int a2i_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *bs, char *buf, int size) | |||
134 | 134 | ||
135 | bufp=(unsigned char *)buf; | 135 | bufp=(unsigned char *)buf; |
136 | if (first) | 136 | if (first) |
137 | { | 137 | { |
138 | first=0; | 138 | first=0; |
139 | if ((bufp[0] == '0') && (buf[1] == '0')) | 139 | if ((bufp[0] == '0') && (buf[1] == '0')) |
140 | { | 140 | { |
141 | bufp+=2; | 141 | bufp+=2; |
142 | i-=2; | 142 | i-=2; |
143 | } | ||
144 | } | 143 | } |
144 | } | ||
145 | k=0; | 145 | k=0; |
146 | i-=again; | 146 | i-=again; |
147 | if (i%2 != 0) | 147 | if (i%2 != 0) |
148 | { | 148 | { |
149 | ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ASN1_R_ODD_NUMBER_OF_CHARS); | 149 | ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ASN1_R_ODD_NUMBER_OF_CHARS); |
150 | goto err; | 150 | goto err; |
151 | } | 151 | } |
152 | i/=2; | 152 | i/=2; |
153 | if (num+i > slen) | 153 | if (num+i > slen) |
154 | { | 154 | { |
155 | if (s == NULL) | 155 | if (s == NULL) |
156 | sp=(unsigned char *)malloc( | 156 | sp=(unsigned char *)malloc( |
157 | (unsigned int)num+i*2); | 157 | (unsigned int)num+i*2); |
@@ -159,18 +159,18 @@ int a2i_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *bs, char *buf, int size) | |||
159 | sp=(unsigned char *)realloc(s, | 159 | sp=(unsigned char *)realloc(s, |
160 | (unsigned int)num+i*2); | 160 | (unsigned int)num+i*2); |
161 | if (sp == NULL) | 161 | if (sp == NULL) |
162 | { | 162 | { |
163 | ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ERR_R_MALLOC_FAILURE); | 163 | ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ERR_R_MALLOC_FAILURE); |
164 | if (s != NULL) free(s); | 164 | if (s != NULL) free(s); |
165 | goto err; | 165 | goto err; |
166 | } | 166 | } |
167 | s=sp; | 167 | s=sp; |
168 | slen=num+i*2; | 168 | slen=num+i*2; |
169 | } | 169 | } |
170 | for (j=0; j<i; j++,k+=2) | 170 | for (j=0; j<i; j++,k+=2) |
171 | { | 171 | { |
172 | for (n=0; n<2; n++) | 172 | for (n=0; n<2; n++) |
173 | { | 173 | { |
174 | m=bufp[k+n]; | 174 | m=bufp[k+n]; |
175 | if ((m >= '0') && (m <= '9')) | 175 | if ((m >= '0') && (m <= '9')) |
176 | m-='0'; | 176 | m-='0'; |
@@ -179,29 +179,29 @@ int a2i_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *bs, char *buf, int size) | |||
179 | else if ((m >= 'A') && (m <= 'F')) | 179 | else if ((m >= 'A') && (m <= 'F')) |
180 | m=m-'A'+10; | 180 | m=m-'A'+10; |
181 | else | 181 | else |
182 | { | 182 | { |
183 | ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ASN1_R_NON_HEX_CHARACTERS); | 183 | ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ASN1_R_NON_HEX_CHARACTERS); |
184 | goto err; | 184 | goto err; |
185 | } | 185 | } |
186 | s[num+j]<<=4; | 186 | s[num+j]<<=4; |
187 | s[num+j]|=m; | 187 | s[num+j]|=m; |
188 | } | ||
189 | } | 188 | } |
189 | } | ||
190 | num+=i; | 190 | num+=i; |
191 | if (again) | 191 | if (again) |
192 | bufsize=BIO_gets(bp,buf,size); | 192 | bufsize=BIO_gets(bp,buf,size); |
193 | else | 193 | else |
194 | break; | 194 | break; |
195 | } | 195 | } |
196 | bs->length=num; | 196 | bs->length=num; |
197 | bs->data=s; | 197 | bs->data=s; |
198 | ret=1; | 198 | ret=1; |
199 | err: | 199 | err: |
200 | if (0) | 200 | if (0) |
201 | { | 201 | { |
202 | err_sl: | 202 | err_sl: |
203 | ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ASN1_R_SHORT_LINE); | 203 | ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ASN1_R_SHORT_LINE); |
204 | } | ||
205 | return(ret); | ||
206 | } | 204 | } |
205 | return(ret); | ||
206 | } | ||
207 | 207 | ||
diff --git a/src/lib/libssl/src/crypto/asn1/f_int.c b/src/lib/libssl/src/crypto/asn1/f_int.c index 977e3d01b7..66632f2dc4 100644 --- a/src/lib/libssl/src/crypto/asn1/f_int.c +++ b/src/lib/libssl/src/crypto/asn1/f_int.c | |||
@@ -62,7 +62,7 @@ | |||
62 | #include <openssl/asn1.h> | 62 | #include <openssl/asn1.h> |
63 | 63 | ||
64 | int i2a_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *a) | 64 | int i2a_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *a) |
65 | { | 65 | { |
66 | int i,n=0; | 66 | int i,n=0; |
67 | static const char *h="0123456789ABCDEF"; | 67 | static const char *h="0123456789ABCDEF"; |
68 | char buf[2]; | 68 | char buf[2]; |
@@ -70,38 +70,38 @@ int i2a_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *a) | |||
70 | if (a == NULL) return(0); | 70 | if (a == NULL) return(0); |
71 | 71 | ||
72 | if (a->type & V_ASN1_NEG) | 72 | if (a->type & V_ASN1_NEG) |
73 | { | 73 | { |
74 | if (BIO_write(bp, "-", 1) != 1) goto err; | 74 | if (BIO_write(bp, "-", 1) != 1) goto err; |
75 | n = 1; | 75 | n = 1; |
76 | } | 76 | } |
77 | 77 | ||
78 | if (a->length == 0) | 78 | if (a->length == 0) |
79 | { | 79 | { |
80 | if (BIO_write(bp,"00",2) != 2) goto err; | 80 | if (BIO_write(bp,"00",2) != 2) goto err; |
81 | n += 2; | 81 | n += 2; |
82 | } | 82 | } |
83 | else | 83 | else |
84 | { | 84 | { |
85 | for (i=0; i<a->length; i++) | 85 | for (i=0; i<a->length; i++) |
86 | { | 86 | { |
87 | if ((i != 0) && (i%35 == 0)) | 87 | if ((i != 0) && (i%35 == 0)) |
88 | { | 88 | { |
89 | if (BIO_write(bp,"\\\n",2) != 2) goto err; | 89 | if (BIO_write(bp,"\\\n",2) != 2) goto err; |
90 | n+=2; | 90 | n+=2; |
91 | } | 91 | } |
92 | buf[0]=h[((unsigned char)a->data[i]>>4)&0x0f]; | 92 | buf[0]=h[((unsigned char)a->data[i]>>4)&0x0f]; |
93 | buf[1]=h[((unsigned char)a->data[i] )&0x0f]; | 93 | buf[1]=h[((unsigned char)a->data[i] )&0x0f]; |
94 | if (BIO_write(bp,buf,2) != 2) goto err; | 94 | if (BIO_write(bp,buf,2) != 2) goto err; |
95 | n+=2; | 95 | n+=2; |
96 | } | ||
97 | } | 96 | } |
97 | } | ||
98 | return(n); | 98 | return(n); |
99 | err: | 99 | err: |
100 | return(-1); | 100 | return(-1); |
101 | } | 101 | } |
102 | 102 | ||
103 | int a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size) | 103 | int a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size) |
104 | { | 104 | { |
105 | int ret=0; | 105 | int ret=0; |
106 | int i,j,k,m,n,again,bufsize; | 106 | int i,j,k,m,n,again,bufsize; |
107 | unsigned char *s=NULL,*sp; | 107 | unsigned char *s=NULL,*sp; |
@@ -112,7 +112,7 @@ int a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size) | |||
112 | 112 | ||
113 | bufsize=BIO_gets(bp,buf,size); | 113 | bufsize=BIO_gets(bp,buf,size); |
114 | for (;;) | 114 | for (;;) |
115 | { | 115 | { |
116 | if (bufsize < 1) goto err_sl; | 116 | if (bufsize < 1) goto err_sl; |
117 | i=bufsize; | 117 | i=bufsize; |
118 | if (buf[i-1] == '\n') buf[--i]='\0'; | 118 | if (buf[i-1] == '\n') buf[--i]='\0'; |
@@ -122,15 +122,15 @@ int a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size) | |||
122 | again=(buf[i-1] == '\\'); | 122 | again=(buf[i-1] == '\\'); |
123 | 123 | ||
124 | for (j=0; j<i; j++) | 124 | for (j=0; j<i; j++) |
125 | { | 125 | { |
126 | if (!( ((buf[j] >= '0') && (buf[j] <= '9')) || | 126 | if (!( ((buf[j] >= '0') && (buf[j] <= '9')) || |
127 | ((buf[j] >= 'a') && (buf[j] <= 'f')) || | 127 | ((buf[j] >= 'a') && (buf[j] <= 'f')) || |
128 | ((buf[j] >= 'A') && (buf[j] <= 'F')))) | 128 | ((buf[j] >= 'A') && (buf[j] <= 'F')))) |
129 | { | 129 | { |
130 | i=j; | 130 | i=j; |
131 | break; | 131 | break; |
132 | } | ||
133 | } | 132 | } |
133 | } | ||
134 | buf[i]='\0'; | 134 | buf[i]='\0'; |
135 | /* We have now cleared all the crap off the end of the | 135 | /* We have now cleared all the crap off the end of the |
136 | * line */ | 136 | * line */ |
@@ -138,42 +138,42 @@ int a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size) | |||
138 | 138 | ||
139 | bufp=(unsigned char *)buf; | 139 | bufp=(unsigned char *)buf; |
140 | if (first) | 140 | if (first) |
141 | { | 141 | { |
142 | first=0; | 142 | first=0; |
143 | if ((bufp[0] == '0') && (buf[1] == '0')) | 143 | if ((bufp[0] == '0') && (buf[1] == '0')) |
144 | { | 144 | { |
145 | bufp+=2; | 145 | bufp+=2; |
146 | i-=2; | 146 | i-=2; |
147 | } | ||
148 | } | 147 | } |
148 | } | ||
149 | k=0; | 149 | k=0; |
150 | i-=again; | 150 | i-=again; |
151 | if (i%2 != 0) | 151 | if (i%2 != 0) |
152 | { | 152 | { |
153 | ASN1err(ASN1_F_A2I_ASN1_INTEGER,ASN1_R_ODD_NUMBER_OF_CHARS); | 153 | ASN1err(ASN1_F_A2I_ASN1_INTEGER,ASN1_R_ODD_NUMBER_OF_CHARS); |
154 | goto err; | 154 | goto err; |
155 | } | 155 | } |
156 | i/=2; | 156 | i/=2; |
157 | if (num+i > slen) | 157 | if (num+i > slen) |
158 | { | 158 | { |
159 | if (s == NULL) | 159 | if (s == NULL) |
160 | sp=(unsigned char *)malloc( | 160 | sp=(unsigned char *)malloc( |
161 | (unsigned int)num+i*2); | 161 | (unsigned int)num+i*2); |
162 | else | 162 | else |
163 | sp=OPENSSL_realloc_clean(s,slen,num+i*2); | 163 | sp=OPENSSL_realloc_clean(s,slen,num+i*2); |
164 | if (sp == NULL) | 164 | if (sp == NULL) |
165 | { | 165 | { |
166 | ASN1err(ASN1_F_A2I_ASN1_INTEGER,ERR_R_MALLOC_FAILURE); | 166 | ASN1err(ASN1_F_A2I_ASN1_INTEGER,ERR_R_MALLOC_FAILURE); |
167 | if (s != NULL) free(s); | 167 | if (s != NULL) free(s); |
168 | goto err; | 168 | goto err; |
169 | } | 169 | } |
170 | s=sp; | 170 | s=sp; |
171 | slen=num+i*2; | 171 | slen=num+i*2; |
172 | } | 172 | } |
173 | for (j=0; j<i; j++,k+=2) | 173 | for (j=0; j<i; j++,k+=2) |
174 | { | 174 | { |
175 | for (n=0; n<2; n++) | 175 | for (n=0; n<2; n++) |
176 | { | 176 | { |
177 | m=bufp[k+n]; | 177 | m=bufp[k+n]; |
178 | if ((m >= '0') && (m <= '9')) | 178 | if ((m >= '0') && (m <= '9')) |
179 | m-='0'; | 179 | m-='0'; |
@@ -182,29 +182,29 @@ int a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size) | |||
182 | else if ((m >= 'A') && (m <= 'F')) | 182 | else if ((m >= 'A') && (m <= 'F')) |
183 | m=m-'A'+10; | 183 | m=m-'A'+10; |
184 | else | 184 | else |
185 | { | 185 | { |
186 | ASN1err(ASN1_F_A2I_ASN1_INTEGER,ASN1_R_NON_HEX_CHARACTERS); | 186 | ASN1err(ASN1_F_A2I_ASN1_INTEGER,ASN1_R_NON_HEX_CHARACTERS); |
187 | goto err; | 187 | goto err; |
188 | } | 188 | } |
189 | s[num+j]<<=4; | 189 | s[num+j]<<=4; |
190 | s[num+j]|=m; | 190 | s[num+j]|=m; |
191 | } | ||
192 | } | 191 | } |
192 | } | ||
193 | num+=i; | 193 | num+=i; |
194 | if (again) | 194 | if (again) |
195 | bufsize=BIO_gets(bp,buf,size); | 195 | bufsize=BIO_gets(bp,buf,size); |
196 | else | 196 | else |
197 | break; | 197 | break; |
198 | } | 198 | } |
199 | bs->length=num; | 199 | bs->length=num; |
200 | bs->data=s; | 200 | bs->data=s; |
201 | ret=1; | 201 | ret=1; |
202 | err: | 202 | err: |
203 | if (0) | 203 | if (0) |
204 | { | 204 | { |
205 | err_sl: | 205 | err_sl: |
206 | ASN1err(ASN1_F_A2I_ASN1_INTEGER,ASN1_R_SHORT_LINE); | 206 | ASN1err(ASN1_F_A2I_ASN1_INTEGER,ASN1_R_SHORT_LINE); |
207 | } | ||
208 | return(ret); | ||
209 | } | 207 | } |
208 | return(ret); | ||
209 | } | ||
210 | 210 | ||
diff --git a/src/lib/libssl/src/crypto/asn1/f_string.c b/src/lib/libssl/src/crypto/asn1/f_string.c index f4bee15335..7a59fa9f4f 100644 --- a/src/lib/libssl/src/crypto/asn1/f_string.c +++ b/src/lib/libssl/src/crypto/asn1/f_string.c | |||
@@ -62,7 +62,7 @@ | |||
62 | #include <openssl/asn1.h> | 62 | #include <openssl/asn1.h> |
63 | 63 | ||
64 | int i2a_ASN1_STRING(BIO *bp, ASN1_STRING *a, int type) | 64 | int i2a_ASN1_STRING(BIO *bp, ASN1_STRING *a, int type) |
65 | { | 65 | { |
66 | int i,n=0; | 66 | int i,n=0; |
67 | static const char *h="0123456789ABCDEF"; | 67 | static const char *h="0123456789ABCDEF"; |
68 | char buf[2]; | 68 | char buf[2]; |
@@ -70,32 +70,32 @@ int i2a_ASN1_STRING(BIO *bp, ASN1_STRING *a, int type) | |||
70 | if (a == NULL) return(0); | 70 | if (a == NULL) return(0); |
71 | 71 | ||
72 | if (a->length == 0) | 72 | if (a->length == 0) |
73 | { | 73 | { |
74 | if (BIO_write(bp,"0",1) != 1) goto err; | 74 | if (BIO_write(bp,"0",1) != 1) goto err; |
75 | n=1; | 75 | n=1; |
76 | } | 76 | } |
77 | else | 77 | else |
78 | { | 78 | { |
79 | for (i=0; i<a->length; i++) | 79 | for (i=0; i<a->length; i++) |
80 | { | 80 | { |
81 | if ((i != 0) && (i%35 == 0)) | 81 | if ((i != 0) && (i%35 == 0)) |
82 | { | 82 | { |
83 | if (BIO_write(bp,"\\\n",2) != 2) goto err; | 83 | if (BIO_write(bp,"\\\n",2) != 2) goto err; |
84 | n+=2; | 84 | n+=2; |
85 | } | 85 | } |
86 | buf[0]=h[((unsigned char)a->data[i]>>4)&0x0f]; | 86 | buf[0]=h[((unsigned char)a->data[i]>>4)&0x0f]; |
87 | buf[1]=h[((unsigned char)a->data[i] )&0x0f]; | 87 | buf[1]=h[((unsigned char)a->data[i] )&0x0f]; |
88 | if (BIO_write(bp,buf,2) != 2) goto err; | 88 | if (BIO_write(bp,buf,2) != 2) goto err; |
89 | n+=2; | 89 | n+=2; |
90 | } | ||
91 | } | 90 | } |
91 | } | ||
92 | return(n); | 92 | return(n); |
93 | err: | 93 | err: |
94 | return(-1); | 94 | return(-1); |
95 | } | 95 | } |
96 | 96 | ||
97 | int a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size) | 97 | int a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size) |
98 | { | 98 | { |
99 | int ret=0; | 99 | int ret=0; |
100 | int i,j,k,m,n,again,bufsize; | 100 | int i,j,k,m,n,again,bufsize; |
101 | unsigned char *s=NULL,*sp; | 101 | unsigned char *s=NULL,*sp; |
@@ -104,14 +104,14 @@ int a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size) | |||
104 | 104 | ||
105 | bufsize=BIO_gets(bp,buf,size); | 105 | bufsize=BIO_gets(bp,buf,size); |
106 | for (;;) | 106 | for (;;) |
107 | { | 107 | { |
108 | if (bufsize < 1) | 108 | if (bufsize < 1) |
109 | { | 109 | { |
110 | if (first) | 110 | if (first) |
111 | break; | 111 | break; |
112 | else | 112 | else |
113 | goto err_sl; | 113 | goto err_sl; |
114 | } | 114 | } |
115 | first=0; | 115 | first=0; |
116 | 116 | ||
117 | i=bufsize; | 117 | i=bufsize; |
@@ -122,15 +122,15 @@ int a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size) | |||
122 | again=(buf[i-1] == '\\'); | 122 | again=(buf[i-1] == '\\'); |
123 | 123 | ||
124 | for (j=i-1; j>0; j--) | 124 | for (j=i-1; j>0; j--) |
125 | { | 125 | { |
126 | if (!( ((buf[j] >= '0') && (buf[j] <= '9')) || | 126 | if (!( ((buf[j] >= '0') && (buf[j] <= '9')) || |
127 | ((buf[j] >= 'a') && (buf[j] <= 'f')) || | 127 | ((buf[j] >= 'a') && (buf[j] <= 'f')) || |
128 | ((buf[j] >= 'A') && (buf[j] <= 'F')))) | 128 | ((buf[j] >= 'A') && (buf[j] <= 'F')))) |
129 | { | 129 | { |
130 | i=j; | 130 | i=j; |
131 | break; | 131 | break; |
132 | } | ||
133 | } | 132 | } |
133 | } | ||
134 | buf[i]='\0'; | 134 | buf[i]='\0'; |
135 | /* We have now cleared all the crap off the end of the | 135 | /* We have now cleared all the crap off the end of the |
136 | * line */ | 136 | * line */ |
@@ -141,13 +141,13 @@ int a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size) | |||
141 | k=0; | 141 | k=0; |
142 | i-=again; | 142 | i-=again; |
143 | if (i%2 != 0) | 143 | if (i%2 != 0) |
144 | { | 144 | { |
145 | ASN1err(ASN1_F_A2I_ASN1_STRING,ASN1_R_ODD_NUMBER_OF_CHARS); | 145 | ASN1err(ASN1_F_A2I_ASN1_STRING,ASN1_R_ODD_NUMBER_OF_CHARS); |
146 | goto err; | 146 | goto err; |
147 | } | 147 | } |
148 | i/=2; | 148 | i/=2; |
149 | if (num+i > slen) | 149 | if (num+i > slen) |
150 | { | 150 | { |
151 | if (s == NULL) | 151 | if (s == NULL) |
152 | sp=(unsigned char *)malloc( | 152 | sp=(unsigned char *)malloc( |
153 | (unsigned int)num+i*2); | 153 | (unsigned int)num+i*2); |
@@ -155,18 +155,18 @@ int a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size) | |||
155 | sp=(unsigned char *)realloc(s, | 155 | sp=(unsigned char *)realloc(s, |
156 | (unsigned int)num+i*2); | 156 | (unsigned int)num+i*2); |
157 | if (sp == NULL) | 157 | if (sp == NULL) |
158 | { | 158 | { |
159 | ASN1err(ASN1_F_A2I_ASN1_STRING,ERR_R_MALLOC_FAILURE); | 159 | ASN1err(ASN1_F_A2I_ASN1_STRING,ERR_R_MALLOC_FAILURE); |
160 | if (s != NULL) free(s); | 160 | if (s != NULL) free(s); |
161 | goto err; | 161 | goto err; |
162 | } | 162 | } |
163 | s=sp; | 163 | s=sp; |
164 | slen=num+i*2; | 164 | slen=num+i*2; |
165 | } | 165 | } |
166 | for (j=0; j<i; j++,k+=2) | 166 | for (j=0; j<i; j++,k+=2) |
167 | { | 167 | { |
168 | for (n=0; n<2; n++) | 168 | for (n=0; n<2; n++) |
169 | { | 169 | { |
170 | m=bufp[k+n]; | 170 | m=bufp[k+n]; |
171 | if ((m >= '0') && (m <= '9')) | 171 | if ((m >= '0') && (m <= '9')) |
172 | m-='0'; | 172 | m-='0'; |
@@ -175,29 +175,29 @@ int a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size) | |||
175 | else if ((m >= 'A') && (m <= 'F')) | 175 | else if ((m >= 'A') && (m <= 'F')) |
176 | m=m-'A'+10; | 176 | m=m-'A'+10; |
177 | else | 177 | else |
178 | { | 178 | { |
179 | ASN1err(ASN1_F_A2I_ASN1_STRING,ASN1_R_NON_HEX_CHARACTERS); | 179 | ASN1err(ASN1_F_A2I_ASN1_STRING,ASN1_R_NON_HEX_CHARACTERS); |
180 | goto err; | 180 | goto err; |
181 | } | 181 | } |
182 | s[num+j]<<=4; | 182 | s[num+j]<<=4; |
183 | s[num+j]|=m; | 183 | s[num+j]|=m; |
184 | } | ||
185 | } | 184 | } |
185 | } | ||
186 | num+=i; | 186 | num+=i; |
187 | if (again) | 187 | if (again) |
188 | bufsize=BIO_gets(bp,buf,size); | 188 | bufsize=BIO_gets(bp,buf,size); |
189 | else | 189 | else |
190 | break; | 190 | break; |
191 | } | 191 | } |
192 | bs->length=num; | 192 | bs->length=num; |
193 | bs->data=s; | 193 | bs->data=s; |
194 | ret=1; | 194 | ret=1; |
195 | err: | 195 | err: |
196 | if (0) | 196 | if (0) |
197 | { | 197 | { |
198 | err_sl: | 198 | err_sl: |
199 | ASN1err(ASN1_F_A2I_ASN1_STRING,ASN1_R_SHORT_LINE); | 199 | ASN1err(ASN1_F_A2I_ASN1_STRING,ASN1_R_SHORT_LINE); |
200 | } | ||
201 | return(ret); | ||
202 | } | 200 | } |
201 | return(ret); | ||
202 | } | ||
203 | 203 | ||
diff --git a/src/lib/libssl/src/crypto/asn1/i2d_pr.c b/src/lib/libssl/src/crypto/asn1/i2d_pr.c index e398b62666..9332c4d2ec 100644 --- a/src/lib/libssl/src/crypto/asn1/i2d_pr.c +++ b/src/lib/libssl/src/crypto/asn1/i2d_pr.c | |||
@@ -63,18 +63,18 @@ | |||
63 | #include "asn1_locl.h" | 63 | #include "asn1_locl.h" |
64 | 64 | ||
65 | int i2d_PrivateKey(EVP_PKEY *a, unsigned char **pp) | 65 | int i2d_PrivateKey(EVP_PKEY *a, unsigned char **pp) |
66 | { | 66 | { |
67 | if (a->ameth && a->ameth->old_priv_encode) | 67 | if (a->ameth && a->ameth->old_priv_encode) |
68 | { | 68 | { |
69 | return a->ameth->old_priv_encode(a, pp); | 69 | return a->ameth->old_priv_encode(a, pp); |
70 | } | 70 | } |
71 | if (a->ameth && a->ameth->priv_encode) { | 71 | if (a->ameth && a->ameth->priv_encode) { |
72 | PKCS8_PRIV_KEY_INFO *p8 = EVP_PKEY2PKCS8(a); | 72 | PKCS8_PRIV_KEY_INFO *p8 = EVP_PKEY2PKCS8(a); |
73 | int ret = i2d_PKCS8_PRIV_KEY_INFO(p8,pp); | 73 | int ret = i2d_PKCS8_PRIV_KEY_INFO(p8,pp); |
74 | PKCS8_PRIV_KEY_INFO_free(p8); | 74 | PKCS8_PRIV_KEY_INFO_free(p8); |
75 | return ret; | 75 | return ret; |
76 | } | 76 | } |
77 | ASN1err(ASN1_F_I2D_PRIVATEKEY,ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE); | 77 | ASN1err(ASN1_F_I2D_PRIVATEKEY,ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE); |
78 | return(-1); | 78 | return(-1); |
79 | } | 79 | } |
80 | 80 | ||
diff --git a/src/lib/libssl/src/crypto/asn1/i2d_pu.c b/src/lib/libssl/src/crypto/asn1/i2d_pu.c index 34286dbd35..ed8ec0753b 100644 --- a/src/lib/libssl/src/crypto/asn1/i2d_pu.c +++ b/src/lib/libssl/src/crypto/asn1/i2d_pu.c | |||
@@ -72,9 +72,9 @@ | |||
72 | #endif | 72 | #endif |
73 | 73 | ||
74 | int i2d_PublicKey(EVP_PKEY *a, unsigned char **pp) | 74 | int i2d_PublicKey(EVP_PKEY *a, unsigned char **pp) |
75 | { | 75 | { |
76 | switch (a->type) | 76 | switch (a->type) |
77 | { | 77 | { |
78 | #ifndef OPENSSL_NO_RSA | 78 | #ifndef OPENSSL_NO_RSA |
79 | case EVP_PKEY_RSA: | 79 | case EVP_PKEY_RSA: |
80 | return(i2d_RSAPublicKey(a->pkey.rsa,pp)); | 80 | return(i2d_RSAPublicKey(a->pkey.rsa,pp)); |
@@ -90,6 +90,6 @@ int i2d_PublicKey(EVP_PKEY *a, unsigned char **pp) | |||
90 | default: | 90 | default: |
91 | ASN1err(ASN1_F_I2D_PUBLICKEY,ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE); | 91 | ASN1err(ASN1_F_I2D_PUBLICKEY,ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE); |
92 | return(-1); | 92 | return(-1); |
93 | } | ||
94 | } | 93 | } |
94 | } | ||
95 | 95 | ||
diff --git a/src/lib/libssl/src/crypto/asn1/n_pkey.c b/src/lib/libssl/src/crypto/asn1/n_pkey.c index 97647d17e1..a59640582e 100644 --- a/src/lib/libssl/src/crypto/asn1/n_pkey.c +++ b/src/lib/libssl/src/crypto/asn1/n_pkey.c | |||
@@ -70,21 +70,21 @@ | |||
70 | #ifndef OPENSSL_NO_RC4 | 70 | #ifndef OPENSSL_NO_RC4 |
71 | 71 | ||
72 | typedef struct netscape_pkey_st | 72 | typedef struct netscape_pkey_st |
73 | { | 73 | { |
74 | long version; | 74 | long version; |
75 | X509_ALGOR *algor; | 75 | X509_ALGOR *algor; |
76 | ASN1_OCTET_STRING *private_key; | 76 | ASN1_OCTET_STRING *private_key; |
77 | } NETSCAPE_PKEY; | 77 | } NETSCAPE_PKEY; |
78 | 78 | ||
79 | typedef struct netscape_encrypted_pkey_st | 79 | typedef struct netscape_encrypted_pkey_st |
80 | { | 80 | { |
81 | ASN1_OCTET_STRING *os; | 81 | ASN1_OCTET_STRING *os; |
82 | /* This is the same structure as DigestInfo so use it: | 82 | /* This is the same structure as DigestInfo so use it: |
83 | * although this isn't really anything to do with | 83 | * although this isn't really anything to do with |
84 | * digests. | 84 | * digests. |
85 | */ | 85 | */ |
86 | X509_SIG *enckey; | 86 | X509_SIG *enckey; |
87 | } NETSCAPE_ENCRYPTED_PKEY; | 87 | } NETSCAPE_ENCRYPTED_PKEY; |
88 | 88 | ||
89 | 89 | ||
90 | ASN1_BROKEN_SEQUENCE(NETSCAPE_ENCRYPTED_PKEY) = { | 90 | ASN1_BROKEN_SEQUENCE(NETSCAPE_ENCRYPTED_PKEY) = { |
@@ -121,7 +121,7 @@ int i2d_Netscape_RSA(const RSA *a, unsigned char **pp, | |||
121 | int i2d_RSA_NET(const RSA *a, unsigned char **pp, | 121 | int i2d_RSA_NET(const RSA *a, unsigned char **pp, |
122 | int (*cb)(char *buf, int len, const char *prompt, int verify), | 122 | int (*cb)(char *buf, int len, const char *prompt, int verify), |
123 | int sgckey) | 123 | int sgckey) |
124 | { | 124 | { |
125 | int i, j, ret = 0; | 125 | int i, j, ret = 0; |
126 | int rsalen, pkeylen, olen; | 126 | int rsalen, pkeylen, olen; |
127 | NETSCAPE_PKEY *pkey = NULL; | 127 | NETSCAPE_PKEY *pkey = NULL; |
@@ -160,36 +160,36 @@ int i2d_RSA_NET(const RSA *a, unsigned char **pp, | |||
160 | enckey->enckey->algor->parameter->type=V_ASN1_NULL; | 160 | enckey->enckey->algor->parameter->type=V_ASN1_NULL; |
161 | 161 | ||
162 | if (pp == NULL) | 162 | if (pp == NULL) |
163 | { | 163 | { |
164 | olen = i2d_NETSCAPE_ENCRYPTED_PKEY(enckey, NULL); | 164 | olen = i2d_NETSCAPE_ENCRYPTED_PKEY(enckey, NULL); |
165 | NETSCAPE_PKEY_free(pkey); | 165 | NETSCAPE_PKEY_free(pkey); |
166 | NETSCAPE_ENCRYPTED_PKEY_free(enckey); | 166 | NETSCAPE_ENCRYPTED_PKEY_free(enckey); |
167 | return olen; | 167 | return olen; |
168 | } | 168 | } |
169 | 169 | ||
170 | 170 | ||
171 | /* Since its RC4 encrypted length is actual length */ | 171 | /* Since its RC4 encrypted length is actual length */ |
172 | if ((zz=(unsigned char *)malloc(rsalen)) == NULL) | 172 | if ((zz=(unsigned char *)malloc(rsalen)) == NULL) |
173 | { | 173 | { |
174 | ASN1err(ASN1_F_I2D_RSA_NET,ERR_R_MALLOC_FAILURE); | 174 | ASN1err(ASN1_F_I2D_RSA_NET,ERR_R_MALLOC_FAILURE); |
175 | goto err; | 175 | goto err; |
176 | } | 176 | } |
177 | 177 | ||
178 | pkey->private_key->data = zz; | 178 | pkey->private_key->data = zz; |
179 | /* Write out private key encoding */ | 179 | /* Write out private key encoding */ |
180 | i2d_RSAPrivateKey(a,&zz); | 180 | i2d_RSAPrivateKey(a,&zz); |
181 | 181 | ||
182 | if ((zz=malloc(pkeylen)) == NULL) | 182 | if ((zz=malloc(pkeylen)) == NULL) |
183 | { | 183 | { |
184 | ASN1err(ASN1_F_I2D_RSA_NET,ERR_R_MALLOC_FAILURE); | 184 | ASN1err(ASN1_F_I2D_RSA_NET,ERR_R_MALLOC_FAILURE); |
185 | goto err; | 185 | goto err; |
186 | } | 186 | } |
187 | 187 | ||
188 | if (!ASN1_STRING_set(enckey->os, "private-key", -1)) | 188 | if (!ASN1_STRING_set(enckey->os, "private-key", -1)) |
189 | { | 189 | { |
190 | ASN1err(ASN1_F_I2D_RSA_NET,ERR_R_MALLOC_FAILURE); | 190 | ASN1err(ASN1_F_I2D_RSA_NET,ERR_R_MALLOC_FAILURE); |
191 | goto err; | 191 | goto err; |
192 | } | 192 | } |
193 | enckey->enckey->digest->data = zz; | 193 | enckey->enckey->digest->data = zz; |
194 | i2d_NETSCAPE_PKEY(pkey,&zz); | 194 | i2d_NETSCAPE_PKEY(pkey,&zz); |
195 | 195 | ||
@@ -200,10 +200,10 @@ int i2d_RSA_NET(const RSA *a, unsigned char **pp, | |||
200 | cb=EVP_read_pw_string; | 200 | cb=EVP_read_pw_string; |
201 | i=cb((char *)buf,256,"Enter Private Key password:",1); | 201 | i=cb((char *)buf,256,"Enter Private Key password:",1); |
202 | if (i != 0) | 202 | if (i != 0) |
203 | { | 203 | { |
204 | ASN1err(ASN1_F_I2D_RSA_NET,ASN1_R_BAD_PASSWORD_READ); | 204 | ASN1err(ASN1_F_I2D_RSA_NET,ASN1_R_BAD_PASSWORD_READ); |
205 | goto err; | 205 | goto err; |
206 | } | 206 | } |
207 | i = strlen((char *)buf); | 207 | i = strlen((char *)buf); |
208 | /* If the key is used for SGC the algorithm is modified a little. */ | 208 | /* If the key is used for SGC the algorithm is modified a little. */ |
209 | if(sgckey) { | 209 | if(sgckey) { |
@@ -211,7 +211,7 @@ int i2d_RSA_NET(const RSA *a, unsigned char **pp, | |||
211 | goto err; | 211 | goto err; |
212 | memcpy(buf + 16, "SGCKEYSALT", 10); | 212 | memcpy(buf + 16, "SGCKEYSALT", 10); |
213 | i = 26; | 213 | i = 26; |
214 | } | 214 | } |
215 | 215 | ||
216 | if (!EVP_BytesToKey(EVP_rc4(),EVP_md5(),NULL,buf,i,1,key,NULL)) | 216 | if (!EVP_BytesToKey(EVP_rc4(),EVP_md5(),NULL,buf,i,1,key,NULL)) |
217 | goto err; | 217 | goto err; |
@@ -232,7 +232,7 @@ err: | |||
232 | NETSCAPE_ENCRYPTED_PKEY_free(enckey); | 232 | NETSCAPE_ENCRYPTED_PKEY_free(enckey); |
233 | NETSCAPE_PKEY_free(pkey); | 233 | NETSCAPE_PKEY_free(pkey); |
234 | return(ret); | 234 | return(ret); |
235 | } | 235 | } |
236 | 236 | ||
237 | 237 | ||
238 | RSA *d2i_Netscape_RSA(RSA **a, const unsigned char **pp, long length, | 238 | RSA *d2i_Netscape_RSA(RSA **a, const unsigned char **pp, long length, |
@@ -245,7 +245,7 @@ RSA *d2i_Netscape_RSA(RSA **a, const unsigned char **pp, long length, | |||
245 | RSA *d2i_RSA_NET(RSA **a, const unsigned char **pp, long length, | 245 | RSA *d2i_RSA_NET(RSA **a, const unsigned char **pp, long length, |
246 | int (*cb)(char *buf, int len, const char *prompt, int verify), | 246 | int (*cb)(char *buf, int len, const char *prompt, int verify), |
247 | int sgckey) | 247 | int sgckey) |
248 | { | 248 | { |
249 | RSA *ret=NULL; | 249 | RSA *ret=NULL; |
250 | const unsigned char *p; | 250 | const unsigned char *p; |
251 | NETSCAPE_ENCRYPTED_PKEY *enckey = NULL; | 251 | NETSCAPE_ENCRYPTED_PKEY *enckey = NULL; |
@@ -256,20 +256,20 @@ RSA *d2i_RSA_NET(RSA **a, const unsigned char **pp, long length, | |||
256 | if(!enckey) { | 256 | if(!enckey) { |
257 | ASN1err(ASN1_F_D2I_RSA_NET,ASN1_R_DECODING_ERROR); | 257 | ASN1err(ASN1_F_D2I_RSA_NET,ASN1_R_DECODING_ERROR); |
258 | return NULL; | 258 | return NULL; |
259 | } | 259 | } |
260 | 260 | ||
261 | if ((enckey->os->length != 11) || (strncmp("private-key", | 261 | if ((enckey->os->length != 11) || (strncmp("private-key", |
262 | (char *)enckey->os->data,11) != 0)) | 262 | (char *)enckey->os->data,11) != 0)) |
263 | { | 263 | { |
264 | ASN1err(ASN1_F_D2I_RSA_NET,ASN1_R_PRIVATE_KEY_HEADER_MISSING); | 264 | ASN1err(ASN1_F_D2I_RSA_NET,ASN1_R_PRIVATE_KEY_HEADER_MISSING); |
265 | NETSCAPE_ENCRYPTED_PKEY_free(enckey); | 265 | NETSCAPE_ENCRYPTED_PKEY_free(enckey); |
266 | return NULL; | 266 | return NULL; |
267 | } | 267 | } |
268 | if (OBJ_obj2nid(enckey->enckey->algor->algorithm) != NID_rc4) | 268 | if (OBJ_obj2nid(enckey->enckey->algor->algorithm) != NID_rc4) |
269 | { | 269 | { |
270 | ASN1err(ASN1_F_D2I_RSA_NET,ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM); | 270 | ASN1err(ASN1_F_D2I_RSA_NET,ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM); |
271 | goto err; | 271 | goto err; |
272 | } | 272 | } |
273 | if (cb == NULL) | 273 | if (cb == NULL) |
274 | cb=EVP_read_pw_string; | 274 | cb=EVP_read_pw_string; |
275 | if ((ret=d2i_RSA_NET_2(a, enckey->enckey->digest,cb, sgckey)) == NULL) goto err; | 275 | if ((ret=d2i_RSA_NET_2(a, enckey->enckey->digest,cb, sgckey)) == NULL) goto err; |
@@ -280,12 +280,12 @@ RSA *d2i_RSA_NET(RSA **a, const unsigned char **pp, long length, | |||
280 | NETSCAPE_ENCRYPTED_PKEY_free(enckey); | 280 | NETSCAPE_ENCRYPTED_PKEY_free(enckey); |
281 | return ret; | 281 | return ret; |
282 | 282 | ||
283 | } | 283 | } |
284 | 284 | ||
285 | static RSA *d2i_RSA_NET_2(RSA **a, ASN1_OCTET_STRING *os, | 285 | static RSA *d2i_RSA_NET_2(RSA **a, ASN1_OCTET_STRING *os, |
286 | int (*cb)(char *buf, int len, const char *prompt, | 286 | int (*cb)(char *buf, int len, const char *prompt, |
287 | int verify), int sgckey) | 287 | int verify), int sgckey) |
288 | { | 288 | { |
289 | NETSCAPE_PKEY *pkey=NULL; | 289 | NETSCAPE_PKEY *pkey=NULL; |
290 | RSA *ret=NULL; | 290 | RSA *ret=NULL; |
291 | int i,j; | 291 | int i,j; |
@@ -297,10 +297,10 @@ static RSA *d2i_RSA_NET_2(RSA **a, ASN1_OCTET_STRING *os, | |||
297 | 297 | ||
298 | i=cb((char *)buf,256,"Enter Private Key password:",0); | 298 | i=cb((char *)buf,256,"Enter Private Key password:",0); |
299 | if (i != 0) | 299 | if (i != 0) |
300 | { | 300 | { |
301 | ASN1err(ASN1_F_D2I_RSA_NET_2,ASN1_R_BAD_PASSWORD_READ); | 301 | ASN1err(ASN1_F_D2I_RSA_NET_2,ASN1_R_BAD_PASSWORD_READ); |
302 | goto err; | 302 | goto err; |
303 | } | 303 | } |
304 | 304 | ||
305 | i = strlen((char *)buf); | 305 | i = strlen((char *)buf); |
306 | if(sgckey){ | 306 | if(sgckey){ |
@@ -308,7 +308,7 @@ static RSA *d2i_RSA_NET_2(RSA **a, ASN1_OCTET_STRING *os, | |||
308 | goto err; | 308 | goto err; |
309 | memcpy(buf + 16, "SGCKEYSALT", 10); | 309 | memcpy(buf + 16, "SGCKEYSALT", 10); |
310 | i = 26; | 310 | i = 26; |
311 | } | 311 | } |
312 | 312 | ||
313 | if (!EVP_BytesToKey(EVP_rc4(),EVP_md5(),NULL,buf,i,1,key,NULL)) | 313 | if (!EVP_BytesToKey(EVP_rc4(),EVP_md5(),NULL,buf,i,1,key,NULL)) |
314 | goto err; | 314 | goto err; |
@@ -325,22 +325,22 @@ static RSA *d2i_RSA_NET_2(RSA **a, ASN1_OCTET_STRING *os, | |||
325 | zz=os->data; | 325 | zz=os->data; |
326 | 326 | ||
327 | if ((pkey=d2i_NETSCAPE_PKEY(NULL,&zz,os->length)) == NULL) | 327 | if ((pkey=d2i_NETSCAPE_PKEY(NULL,&zz,os->length)) == NULL) |
328 | { | 328 | { |
329 | ASN1err(ASN1_F_D2I_RSA_NET_2,ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY); | 329 | ASN1err(ASN1_F_D2I_RSA_NET_2,ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY); |
330 | goto err; | 330 | goto err; |
331 | } | 331 | } |
332 | 332 | ||
333 | zz=pkey->private_key->data; | 333 | zz=pkey->private_key->data; |
334 | if ((ret=d2i_RSAPrivateKey(a,&zz,pkey->private_key->length)) == NULL) | 334 | if ((ret=d2i_RSAPrivateKey(a,&zz,pkey->private_key->length)) == NULL) |
335 | { | 335 | { |
336 | ASN1err(ASN1_F_D2I_RSA_NET_2,ASN1_R_UNABLE_TO_DECODE_RSA_KEY); | 336 | ASN1err(ASN1_F_D2I_RSA_NET_2,ASN1_R_UNABLE_TO_DECODE_RSA_KEY); |
337 | goto err; | 337 | goto err; |
338 | } | 338 | } |
339 | err: | 339 | err: |
340 | EVP_CIPHER_CTX_cleanup(&ctx); | 340 | EVP_CIPHER_CTX_cleanup(&ctx); |
341 | NETSCAPE_PKEY_free(pkey); | 341 | NETSCAPE_PKEY_free(pkey); |
342 | return(ret); | 342 | return(ret); |
343 | } | 343 | } |
344 | 344 | ||
345 | #endif /* OPENSSL_NO_RC4 */ | 345 | #endif /* OPENSSL_NO_RC4 */ |
346 | 346 | ||
diff --git a/src/lib/libssl/src/crypto/asn1/p5_pbe.c b/src/lib/libssl/src/crypto/asn1/p5_pbe.c index 94bc38b99f..f0f23c668d 100644 --- a/src/lib/libssl/src/crypto/asn1/p5_pbe.c +++ b/src/lib/libssl/src/crypto/asn1/p5_pbe.c | |||
@@ -76,31 +76,31 @@ IMPLEMENT_ASN1_FUNCTIONS(PBEPARAM) | |||
76 | 76 | ||
77 | int PKCS5_pbe_set0_algor(X509_ALGOR *algor, int alg, int iter, | 77 | int PKCS5_pbe_set0_algor(X509_ALGOR *algor, int alg, int iter, |
78 | const unsigned char *salt, int saltlen) | 78 | const unsigned char *salt, int saltlen) |
79 | { | 79 | { |
80 | PBEPARAM *pbe=NULL; | 80 | PBEPARAM *pbe=NULL; |
81 | ASN1_STRING *pbe_str=NULL; | 81 | ASN1_STRING *pbe_str=NULL; |
82 | unsigned char *sstr; | 82 | unsigned char *sstr; |
83 | 83 | ||
84 | pbe = PBEPARAM_new(); | 84 | pbe = PBEPARAM_new(); |
85 | if (!pbe) | 85 | if (!pbe) |
86 | { | 86 | { |
87 | ASN1err(ASN1_F_PKCS5_PBE_SET0_ALGOR,ERR_R_MALLOC_FAILURE); | 87 | ASN1err(ASN1_F_PKCS5_PBE_SET0_ALGOR,ERR_R_MALLOC_FAILURE); |
88 | goto err; | 88 | goto err; |
89 | } | 89 | } |
90 | if(iter <= 0) | 90 | if(iter <= 0) |
91 | iter = PKCS5_DEFAULT_ITER; | 91 | iter = PKCS5_DEFAULT_ITER; |
92 | if (!ASN1_INTEGER_set(pbe->iter, iter)) | 92 | if (!ASN1_INTEGER_set(pbe->iter, iter)) |
93 | { | 93 | { |
94 | ASN1err(ASN1_F_PKCS5_PBE_SET0_ALGOR,ERR_R_MALLOC_FAILURE); | 94 | ASN1err(ASN1_F_PKCS5_PBE_SET0_ALGOR,ERR_R_MALLOC_FAILURE); |
95 | goto err; | 95 | goto err; |
96 | } | 96 | } |
97 | if (!saltlen) | 97 | if (!saltlen) |
98 | saltlen = PKCS5_SALT_LEN; | 98 | saltlen = PKCS5_SALT_LEN; |
99 | if (!ASN1_STRING_set(pbe->salt, NULL, saltlen)) | 99 | if (!ASN1_STRING_set(pbe->salt, NULL, saltlen)) |
100 | { | 100 | { |
101 | ASN1err(ASN1_F_PKCS5_PBE_SET0_ALGOR,ERR_R_MALLOC_FAILURE); | 101 | ASN1err(ASN1_F_PKCS5_PBE_SET0_ALGOR,ERR_R_MALLOC_FAILURE); |
102 | goto err; | 102 | goto err; |
103 | } | 103 | } |
104 | sstr = ASN1_STRING_data(pbe->salt); | 104 | sstr = ASN1_STRING_data(pbe->salt); |
105 | if (salt) | 105 | if (salt) |
106 | memcpy(sstr, salt, saltlen); | 106 | memcpy(sstr, salt, saltlen); |
@@ -108,10 +108,10 @@ int PKCS5_pbe_set0_algor(X509_ALGOR *algor, int alg, int iter, | |||
108 | goto err; | 108 | goto err; |
109 | 109 | ||
110 | if(!ASN1_item_pack(pbe, ASN1_ITEM_rptr(PBEPARAM), &pbe_str)) | 110 | if(!ASN1_item_pack(pbe, ASN1_ITEM_rptr(PBEPARAM), &pbe_str)) |
111 | { | 111 | { |
112 | ASN1err(ASN1_F_PKCS5_PBE_SET0_ALGOR,ERR_R_MALLOC_FAILURE); | 112 | ASN1err(ASN1_F_PKCS5_PBE_SET0_ALGOR,ERR_R_MALLOC_FAILURE); |
113 | goto err; | 113 | goto err; |
114 | } | 114 | } |
115 | 115 | ||
116 | PBEPARAM_free(pbe); | 116 | PBEPARAM_free(pbe); |
117 | pbe = NULL; | 117 | pbe = NULL; |
@@ -125,24 +125,24 @@ err: | |||
125 | if (pbe_str != NULL) | 125 | if (pbe_str != NULL) |
126 | ASN1_STRING_free(pbe_str); | 126 | ASN1_STRING_free(pbe_str); |
127 | return 0; | 127 | return 0; |
128 | } | 128 | } |
129 | 129 | ||
130 | /* Return an algorithm identifier for a PKCS#5 PBE algorithm */ | 130 | /* Return an algorithm identifier for a PKCS#5 PBE algorithm */ |
131 | 131 | ||
132 | X509_ALGOR *PKCS5_pbe_set(int alg, int iter, | 132 | X509_ALGOR *PKCS5_pbe_set(int alg, int iter, |
133 | const unsigned char *salt, int saltlen) | 133 | const unsigned char *salt, int saltlen) |
134 | { | 134 | { |
135 | X509_ALGOR *ret; | 135 | X509_ALGOR *ret; |
136 | ret = X509_ALGOR_new(); | 136 | ret = X509_ALGOR_new(); |
137 | if (!ret) | 137 | if (!ret) |
138 | { | 138 | { |
139 | ASN1err(ASN1_F_PKCS5_PBE_SET,ERR_R_MALLOC_FAILURE); | 139 | ASN1err(ASN1_F_PKCS5_PBE_SET,ERR_R_MALLOC_FAILURE); |
140 | return NULL; | 140 | return NULL; |
141 | } | 141 | } |
142 | 142 | ||
143 | if (PKCS5_pbe_set0_algor(ret, alg, iter, salt, saltlen)) | 143 | if (PKCS5_pbe_set0_algor(ret, alg, iter, salt, saltlen)) |
144 | return ret; | 144 | return ret; |
145 | 145 | ||
146 | X509_ALGOR_free(ret); | 146 | X509_ALGOR_free(ret); |
147 | return NULL; | 147 | return NULL; |
148 | } | 148 | } |
diff --git a/src/lib/libssl/src/crypto/asn1/p8_pkey.c b/src/lib/libssl/src/crypto/asn1/p8_pkey.c index 17b68d386d..9d26cf51ec 100644 --- a/src/lib/libssl/src/crypto/asn1/p8_pkey.c +++ b/src/lib/libssl/src/crypto/asn1/p8_pkey.c | |||
@@ -71,7 +71,7 @@ static int pkey_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, | |||
71 | if (key->pkey->value.octet_string) | 71 | if (key->pkey->value.octet_string) |
72 | OPENSSL_cleanse(key->pkey->value.octet_string->data, | 72 | OPENSSL_cleanse(key->pkey->value.octet_string->data, |
73 | key->pkey->value.octet_string->length); | 73 | key->pkey->value.octet_string->length); |
74 | } | 74 | } |
75 | return 1; | 75 | return 1; |
76 | } | 76 | } |
77 | 77 | ||
@@ -88,15 +88,15 @@ int PKCS8_pkey_set0(PKCS8_PRIV_KEY_INFO *priv, ASN1_OBJECT *aobj, | |||
88 | int version, | 88 | int version, |
89 | int ptype, void *pval, | 89 | int ptype, void *pval, |
90 | unsigned char *penc, int penclen) | 90 | unsigned char *penc, int penclen) |
91 | { | 91 | { |
92 | unsigned char **ppenc = NULL; | 92 | unsigned char **ppenc = NULL; |
93 | if (version >= 0) | 93 | if (version >= 0) |
94 | { | 94 | { |
95 | if (!ASN1_INTEGER_set(priv->version, version)) | 95 | if (!ASN1_INTEGER_set(priv->version, version)) |
96 | return 0; | 96 | return 0; |
97 | } | 97 | } |
98 | if (penc) | 98 | if (penc) |
99 | { | 99 | { |
100 | int pmtype; | 100 | int pmtype; |
101 | ASN1_OCTET_STRING *oct; | 101 | ASN1_OCTET_STRING *oct; |
102 | oct = ASN1_OCTET_STRING_new(); | 102 | oct = ASN1_OCTET_STRING_new(); |
@@ -110,46 +110,46 @@ int PKCS8_pkey_set0(PKCS8_PRIV_KEY_INFO *priv, ASN1_OBJECT *aobj, | |||
110 | else | 110 | else |
111 | pmtype = V_ASN1_OCTET_STRING; | 111 | pmtype = V_ASN1_OCTET_STRING; |
112 | ASN1_TYPE_set(priv->pkey, pmtype, oct); | 112 | ASN1_TYPE_set(priv->pkey, pmtype, oct); |
113 | } | 113 | } |
114 | if (!X509_ALGOR_set0(priv->pkeyalg, aobj, ptype, pval)) | 114 | if (!X509_ALGOR_set0(priv->pkeyalg, aobj, ptype, pval)) |
115 | { | 115 | { |
116 | /* If call fails do not swallow 'enc' */ | 116 | /* If call fails do not swallow 'enc' */ |
117 | if (ppenc) | 117 | if (ppenc) |
118 | *ppenc = NULL; | 118 | *ppenc = NULL; |
119 | return 0; | 119 | return 0; |
120 | } | ||
121 | return 1; | ||
122 | } | 120 | } |
121 | return 1; | ||
122 | } | ||
123 | 123 | ||
124 | int PKCS8_pkey_get0(ASN1_OBJECT **ppkalg, | 124 | int PKCS8_pkey_get0(ASN1_OBJECT **ppkalg, |
125 | const unsigned char **pk, int *ppklen, | 125 | const unsigned char **pk, int *ppklen, |
126 | X509_ALGOR **pa, | 126 | X509_ALGOR **pa, |
127 | PKCS8_PRIV_KEY_INFO *p8) | 127 | PKCS8_PRIV_KEY_INFO *p8) |
128 | { | 128 | { |
129 | if (ppkalg) | 129 | if (ppkalg) |
130 | *ppkalg = p8->pkeyalg->algorithm; | 130 | *ppkalg = p8->pkeyalg->algorithm; |
131 | if(p8->pkey->type == V_ASN1_OCTET_STRING) | 131 | if(p8->pkey->type == V_ASN1_OCTET_STRING) |
132 | { | 132 | { |
133 | p8->broken = PKCS8_OK; | 133 | p8->broken = PKCS8_OK; |
134 | if (pk) | 134 | if (pk) |
135 | { | 135 | { |
136 | *pk = p8->pkey->value.octet_string->data; | 136 | *pk = p8->pkey->value.octet_string->data; |
137 | *ppklen = p8->pkey->value.octet_string->length; | 137 | *ppklen = p8->pkey->value.octet_string->length; |
138 | } | ||
139 | } | 138 | } |
139 | } | ||
140 | else if (p8->pkey->type == V_ASN1_SEQUENCE) | 140 | else if (p8->pkey->type == V_ASN1_SEQUENCE) |
141 | { | 141 | { |
142 | p8->broken = PKCS8_NO_OCTET; | 142 | p8->broken = PKCS8_NO_OCTET; |
143 | if (pk) | 143 | if (pk) |
144 | { | 144 | { |
145 | *pk = p8->pkey->value.sequence->data; | 145 | *pk = p8->pkey->value.sequence->data; |
146 | *ppklen = p8->pkey->value.sequence->length; | 146 | *ppklen = p8->pkey->value.sequence->length; |
147 | } | ||
148 | } | 147 | } |
148 | } | ||
149 | else | 149 | else |
150 | return 0; | 150 | return 0; |
151 | if (pa) | 151 | if (pa) |
152 | *pa = p8->pkeyalg; | 152 | *pa = p8->pkeyalg; |
153 | return 1; | 153 | return 1; |
154 | } | 154 | } |
155 | 155 | ||
diff --git a/src/lib/libssl/src/crypto/asn1/t_crl.c b/src/lib/libssl/src/crypto/asn1/t_crl.c index f6550b2b04..1624cc5fcc 100644 --- a/src/lib/libssl/src/crypto/asn1/t_crl.c +++ b/src/lib/libssl/src/crypto/asn1/t_crl.c | |||
@@ -66,20 +66,20 @@ | |||
66 | 66 | ||
67 | #ifndef OPENSSL_NO_FP_API | 67 | #ifndef OPENSSL_NO_FP_API |
68 | int X509_CRL_print_fp(FILE *fp, X509_CRL *x) | 68 | int X509_CRL_print_fp(FILE *fp, X509_CRL *x) |
69 | { | 69 | { |
70 | BIO *b; | 70 | BIO *b; |
71 | int ret; | 71 | int ret; |
72 | 72 | ||
73 | if ((b=BIO_new(BIO_s_file())) == NULL) | 73 | if ((b=BIO_new(BIO_s_file())) == NULL) |
74 | { | 74 | { |
75 | X509err(X509_F_X509_CRL_PRINT_FP,ERR_R_BUF_LIB); | 75 | X509err(X509_F_X509_CRL_PRINT_FP,ERR_R_BUF_LIB); |
76 | return(0); | 76 | return(0); |
77 | } | 77 | } |
78 | BIO_set_fp(b,fp,BIO_NOCLOSE); | 78 | BIO_set_fp(b,fp,BIO_NOCLOSE); |
79 | ret=X509_CRL_print(b, x); | 79 | ret=X509_CRL_print(b, x); |
80 | BIO_free(b); | 80 | BIO_free(b); |
81 | return(ret); | 81 | return(ret); |
82 | } | 82 | } |
83 | #endif | 83 | #endif |
84 | 84 | ||
85 | int X509_CRL_print(BIO *out, X509_CRL *x) | 85 | int X509_CRL_print(BIO *out, X509_CRL *x) |
diff --git a/src/lib/libssl/src/crypto/asn1/t_pkey.c b/src/lib/libssl/src/crypto/asn1/t_pkey.c index 9dd18f6579..61f5cd61f1 100644 --- a/src/lib/libssl/src/crypto/asn1/t_pkey.c +++ b/src/lib/libssl/src/crypto/asn1/t_pkey.c | |||
@@ -64,7 +64,7 @@ | |||
64 | 64 | ||
65 | int ASN1_bn_print(BIO *bp, const char *number, const BIGNUM *num, | 65 | int ASN1_bn_print(BIO *bp, const char *number, const BIGNUM *num, |
66 | unsigned char *buf, int off) | 66 | unsigned char *buf, int off) |
67 | { | 67 | { |
68 | int n,i; | 68 | int n,i; |
69 | const char *neg; | 69 | const char *neg; |
70 | 70 | ||
@@ -73,20 +73,20 @@ int ASN1_bn_print(BIO *bp, const char *number, const BIGNUM *num, | |||
73 | if(!BIO_indent(bp,off,128)) | 73 | if(!BIO_indent(bp,off,128)) |
74 | return 0; | 74 | return 0; |
75 | if (BN_is_zero(num)) | 75 | if (BN_is_zero(num)) |
76 | { | 76 | { |
77 | if (BIO_printf(bp, "%s 0\n", number) <= 0) | 77 | if (BIO_printf(bp, "%s 0\n", number) <= 0) |
78 | return 0; | 78 | return 0; |
79 | return 1; | 79 | return 1; |
80 | } | 80 | } |
81 | 81 | ||
82 | if (BN_num_bytes(num) <= BN_BYTES) | 82 | if (BN_num_bytes(num) <= BN_BYTES) |
83 | { | 83 | { |
84 | if (BIO_printf(bp,"%s %s%lu (%s0x%lx)\n",number,neg, | 84 | if (BIO_printf(bp,"%s %s%lu (%s0x%lx)\n",number,neg, |
85 | (unsigned long)num->d[0],neg,(unsigned long)num->d[0]) | 85 | (unsigned long)num->d[0],neg,(unsigned long)num->d[0]) |
86 | <= 0) return(0); | 86 | <= 0) return(0); |
87 | } | 87 | } |
88 | else | 88 | else |
89 | { | 89 | { |
90 | buf[0]=0; | 90 | buf[0]=0; |
91 | if (BIO_printf(bp,"%s%s",number, | 91 | if (BIO_printf(bp,"%s%s",number, |
92 | (neg[0] == '-')?" (Negative)":"") <= 0) | 92 | (neg[0] == '-')?" (Negative)":"") <= 0) |
@@ -98,17 +98,17 @@ int ASN1_bn_print(BIO *bp, const char *number, const BIGNUM *num, | |||
98 | else buf++; | 98 | else buf++; |
99 | 99 | ||
100 | for (i=0; i<n; i++) | 100 | for (i=0; i<n; i++) |
101 | { | 101 | { |
102 | if ((i%15) == 0) | 102 | if ((i%15) == 0) |
103 | { | 103 | { |
104 | if(BIO_puts(bp,"\n") <= 0 | 104 | if(BIO_puts(bp,"\n") <= 0 |
105 | || !BIO_indent(bp,off+4,128)) | 105 | || !BIO_indent(bp,off+4,128)) |
106 | return 0; | 106 | return 0; |
107 | } | 107 | } |
108 | if (BIO_printf(bp,"%02x%s",buf[i],((i+1) == n)?"":":") | 108 | if (BIO_printf(bp,"%02x%s",buf[i],((i+1) == n)?"":":") |
109 | <= 0) return(0); | 109 | <= 0) return(0); |
110 | } | ||
111 | if (BIO_write(bp,"\n",1) <= 0) return(0); | ||
112 | } | 110 | } |
113 | return(1); | 111 | if (BIO_write(bp,"\n",1) <= 0) return(0); |
114 | } | 112 | } |
113 | return(1); | ||
114 | } | ||
diff --git a/src/lib/libssl/src/crypto/asn1/t_req.c b/src/lib/libssl/src/crypto/asn1/t_req.c index ea1794e3e0..a863543898 100644 --- a/src/lib/libssl/src/crypto/asn1/t_req.c +++ b/src/lib/libssl/src/crypto/asn1/t_req.c | |||
@@ -72,24 +72,24 @@ | |||
72 | 72 | ||
73 | #ifndef OPENSSL_NO_FP_API | 73 | #ifndef OPENSSL_NO_FP_API |
74 | int X509_REQ_print_fp(FILE *fp, X509_REQ *x) | 74 | int X509_REQ_print_fp(FILE *fp, X509_REQ *x) |
75 | { | 75 | { |
76 | BIO *b; | 76 | BIO *b; |
77 | int ret; | 77 | int ret; |
78 | 78 | ||
79 | if ((b=BIO_new(BIO_s_file())) == NULL) | 79 | if ((b=BIO_new(BIO_s_file())) == NULL) |
80 | { | 80 | { |
81 | X509err(X509_F_X509_REQ_PRINT_FP,ERR_R_BUF_LIB); | 81 | X509err(X509_F_X509_REQ_PRINT_FP,ERR_R_BUF_LIB); |
82 | return(0); | 82 | return(0); |
83 | } | 83 | } |
84 | BIO_set_fp(b,fp,BIO_NOCLOSE); | 84 | BIO_set_fp(b,fp,BIO_NOCLOSE); |
85 | ret=X509_REQ_print(b, x); | 85 | ret=X509_REQ_print(b, x); |
86 | BIO_free(b); | 86 | BIO_free(b); |
87 | return(ret); | 87 | return(ret); |
88 | } | 88 | } |
89 | #endif | 89 | #endif |
90 | 90 | ||
91 | int X509_REQ_print_ex(BIO *bp, X509_REQ *x, unsigned long nmflags, unsigned long cflag) | 91 | int X509_REQ_print_ex(BIO *bp, X509_REQ *x, unsigned long nmflags, unsigned long cflag) |
92 | { | 92 | { |
93 | unsigned long l; | 93 | unsigned long l; |
94 | int i; | 94 | int i; |
95 | const char *neg; | 95 | const char *neg; |
@@ -111,20 +111,20 @@ int X509_REQ_print_ex(BIO *bp, X509_REQ *x, unsigned long nmflags, unsigned long | |||
111 | 111 | ||
112 | ri=x->req_info; | 112 | ri=x->req_info; |
113 | if(!(cflag & X509_FLAG_NO_HEADER)) | 113 | if(!(cflag & X509_FLAG_NO_HEADER)) |
114 | { | 114 | { |
115 | if (BIO_write(bp,"Certificate Request:\n",21) <= 0) goto err; | 115 | if (BIO_write(bp,"Certificate Request:\n",21) <= 0) goto err; |
116 | if (BIO_write(bp," Data:\n",10) <= 0) goto err; | 116 | if (BIO_write(bp," Data:\n",10) <= 0) goto err; |
117 | } | 117 | } |
118 | if(!(cflag & X509_FLAG_NO_VERSION)) | 118 | if(!(cflag & X509_FLAG_NO_VERSION)) |
119 | { | 119 | { |
120 | neg=(ri->version->type == V_ASN1_NEG_INTEGER)?"-":""; | 120 | neg=(ri->version->type == V_ASN1_NEG_INTEGER)?"-":""; |
121 | l=0; | 121 | l=0; |
122 | for (i=0; i<ri->version->length; i++) | 122 | for (i=0; i<ri->version->length; i++) |
123 | { l<<=8; l+=ri->version->data[i]; } | 123 | { l<<=8; l+=ri->version->data[i]; } |
124 | if(BIO_printf(bp,"%8sVersion: %s%lu (%s0x%lx)\n","",neg,l,neg, | 124 | if(BIO_printf(bp,"%8sVersion: %s%lu (%s0x%lx)\n","",neg,l,neg, |
125 | l) <= 0) | 125 | l) <= 0) |
126 | goto err; | 126 | goto err; |
127 | } | 127 | } |
128 | if(!(cflag & X509_FLAG_NO_SUBJECT)) | 128 | if(!(cflag & X509_FLAG_NO_SUBJECT)) |
129 | { | 129 | { |
130 | if (BIO_printf(bp," Subject:%c",mlch) <= 0) goto err; | 130 | if (BIO_printf(bp," Subject:%c",mlch) <= 0) goto err; |
@@ -132,7 +132,7 @@ int X509_REQ_print_ex(BIO *bp, X509_REQ *x, unsigned long nmflags, unsigned long | |||
132 | if (BIO_write(bp,"\n",1) <= 0) goto err; | 132 | if (BIO_write(bp,"\n",1) <= 0) goto err; |
133 | } | 133 | } |
134 | if(!(cflag & X509_FLAG_NO_PUBKEY)) | 134 | if(!(cflag & X509_FLAG_NO_PUBKEY)) |
135 | { | 135 | { |
136 | if (BIO_write(bp," Subject Public Key Info:\n",33) <= 0) | 136 | if (BIO_write(bp," Subject Public Key Info:\n",33) <= 0) |
137 | goto err; | 137 | goto err; |
138 | if (BIO_printf(bp,"%12sPublic Key Algorithm: ","") <= 0) | 138 | if (BIO_printf(bp,"%12sPublic Key Algorithm: ","") <= 0) |
@@ -144,33 +144,33 @@ int X509_REQ_print_ex(BIO *bp, X509_REQ *x, unsigned long nmflags, unsigned long | |||
144 | 144 | ||
145 | pkey=X509_REQ_get_pubkey(x); | 145 | pkey=X509_REQ_get_pubkey(x); |
146 | if (pkey == NULL) | 146 | if (pkey == NULL) |
147 | { | 147 | { |
148 | BIO_printf(bp,"%12sUnable to load Public Key\n",""); | 148 | BIO_printf(bp,"%12sUnable to load Public Key\n",""); |
149 | ERR_print_errors(bp); | 149 | ERR_print_errors(bp); |
150 | } | 150 | } |
151 | else | 151 | else |
152 | { | 152 | { |
153 | EVP_PKEY_print_public(bp, pkey, 16, NULL); | 153 | EVP_PKEY_print_public(bp, pkey, 16, NULL); |
154 | EVP_PKEY_free(pkey); | 154 | EVP_PKEY_free(pkey); |
155 | } | ||
156 | } | 155 | } |
156 | } | ||
157 | 157 | ||
158 | if(!(cflag & X509_FLAG_NO_ATTRIBUTES)) | 158 | if(!(cflag & X509_FLAG_NO_ATTRIBUTES)) |
159 | { | 159 | { |
160 | /* may not be */ | 160 | /* may not be */ |
161 | if(BIO_printf(bp,"%8sAttributes:\n","") <= 0) | 161 | if(BIO_printf(bp,"%8sAttributes:\n","") <= 0) |
162 | goto err; | 162 | goto err; |
163 | 163 | ||
164 | sk=x->req_info->attributes; | 164 | sk=x->req_info->attributes; |
165 | if (sk_X509_ATTRIBUTE_num(sk) == 0) | 165 | if (sk_X509_ATTRIBUTE_num(sk) == 0) |
166 | { | 166 | { |
167 | if(BIO_printf(bp,"%12sa0:00\n","") <= 0) | 167 | if(BIO_printf(bp,"%12sa0:00\n","") <= 0) |
168 | goto err; | 168 | goto err; |
169 | } | 169 | } |
170 | else | 170 | else |
171 | { | 171 | { |
172 | for (i=0; i<sk_X509_ATTRIBUTE_num(sk); i++) | 172 | for (i=0; i<sk_X509_ATTRIBUTE_num(sk); i++) |
173 | { | 173 | { |
174 | ASN1_TYPE *at; | 174 | ASN1_TYPE *at; |
175 | X509_ATTRIBUTE *a; | 175 | X509_ATTRIBUTE *a; |
176 | ASN1_BIT_STRING *bs=NULL; | 176 | ASN1_BIT_STRING *bs=NULL; |
@@ -183,51 +183,51 @@ int X509_REQ_print_ex(BIO *bp, X509_REQ *x, unsigned long nmflags, unsigned long | |||
183 | if(BIO_printf(bp,"%12s","") <= 0) | 183 | if(BIO_printf(bp,"%12s","") <= 0) |
184 | goto err; | 184 | goto err; |
185 | if ((j=i2a_ASN1_OBJECT(bp,a->object)) > 0) | 185 | if ((j=i2a_ASN1_OBJECT(bp,a->object)) > 0) |
186 | { | 186 | { |
187 | if (a->single) | 187 | if (a->single) |
188 | { | 188 | { |
189 | t=a->value.single; | 189 | t=a->value.single; |
190 | type=t->type; | 190 | type=t->type; |
191 | bs=t->value.bit_string; | 191 | bs=t->value.bit_string; |
192 | } | 192 | } |
193 | else | 193 | else |
194 | { | 194 | { |
195 | ii=0; | 195 | ii=0; |
196 | count=sk_ASN1_TYPE_num(a->value.set); | 196 | count=sk_ASN1_TYPE_num(a->value.set); |
197 | get_next: | 197 | get_next: |
198 | at=sk_ASN1_TYPE_value(a->value.set,ii); | 198 | at=sk_ASN1_TYPE_value(a->value.set,ii); |
199 | type=at->type; | 199 | type=at->type; |
200 | bs=at->value.asn1_string; | 200 | bs=at->value.asn1_string; |
201 | } | ||
202 | } | 201 | } |
202 | } | ||
203 | for (j=25-j; j>0; j--) | 203 | for (j=25-j; j>0; j--) |
204 | if (BIO_write(bp," ",1) != 1) goto err; | 204 | if (BIO_write(bp," ",1) != 1) goto err; |
205 | if (BIO_puts(bp,":") <= 0) goto err; | 205 | if (BIO_puts(bp,":") <= 0) goto err; |
206 | if ( (type == V_ASN1_PRINTABLESTRING) || | 206 | if ( (type == V_ASN1_PRINTABLESTRING) || |
207 | (type == V_ASN1_T61STRING) || | 207 | (type == V_ASN1_T61STRING) || |
208 | (type == V_ASN1_IA5STRING)) | 208 | (type == V_ASN1_IA5STRING)) |
209 | { | 209 | { |
210 | if (BIO_write(bp,(char *)bs->data,bs->length) | 210 | if (BIO_write(bp,(char *)bs->data,bs->length) |
211 | != bs->length) | 211 | != bs->length) |
212 | goto err; | 212 | goto err; |
213 | BIO_puts(bp,"\n"); | 213 | BIO_puts(bp,"\n"); |
214 | } | 214 | } |
215 | else | 215 | else |
216 | { | 216 | { |
217 | BIO_puts(bp,"unable to print attribute\n"); | 217 | BIO_puts(bp,"unable to print attribute\n"); |
218 | } | ||
219 | if (++ii < count) goto get_next; | ||
220 | } | 218 | } |
219 | if (++ii < count) goto get_next; | ||
221 | } | 220 | } |
222 | } | 221 | } |
222 | } | ||
223 | if(!(cflag & X509_FLAG_NO_EXTENSIONS)) | 223 | if(!(cflag & X509_FLAG_NO_EXTENSIONS)) |
224 | { | 224 | { |
225 | exts = X509_REQ_get_extensions(x); | 225 | exts = X509_REQ_get_extensions(x); |
226 | if(exts) | 226 | if(exts) |
227 | { | 227 | { |
228 | BIO_printf(bp,"%8sRequested Extensions:\n",""); | 228 | BIO_printf(bp,"%8sRequested Extensions:\n",""); |
229 | for (i=0; i<sk_X509_EXTENSION_num(exts); i++) | 229 | for (i=0; i<sk_X509_EXTENSION_num(exts); i++) |
230 | { | 230 | { |
231 | ASN1_OBJECT *obj; | 231 | ASN1_OBJECT *obj; |
232 | X509_EXTENSION *ex; | 232 | X509_EXTENSION *ex; |
233 | int j; | 233 | int j; |
@@ -239,28 +239,28 @@ get_next: | |||
239 | if (BIO_printf(bp,": %s\n",j?"critical":"") <= 0) | 239 | if (BIO_printf(bp,": %s\n",j?"critical":"") <= 0) |
240 | goto err; | 240 | goto err; |
241 | if(!X509V3_EXT_print(bp, ex, cflag, 16)) | 241 | if(!X509V3_EXT_print(bp, ex, cflag, 16)) |
242 | { | 242 | { |
243 | BIO_printf(bp, "%16s", ""); | 243 | BIO_printf(bp, "%16s", ""); |
244 | M_ASN1_OCTET_STRING_print(bp,ex->value); | 244 | M_ASN1_OCTET_STRING_print(bp,ex->value); |
245 | } | ||
246 | if (BIO_write(bp,"\n",1) <= 0) goto err; | ||
247 | } | 245 | } |
248 | sk_X509_EXTENSION_pop_free(exts, X509_EXTENSION_free); | 246 | if (BIO_write(bp,"\n",1) <= 0) goto err; |
249 | } | 247 | } |
248 | sk_X509_EXTENSION_pop_free(exts, X509_EXTENSION_free); | ||
250 | } | 249 | } |
250 | } | ||
251 | 251 | ||
252 | if(!(cflag & X509_FLAG_NO_SIGDUMP)) | 252 | if(!(cflag & X509_FLAG_NO_SIGDUMP)) |
253 | { | 253 | { |
254 | if(!X509_signature_print(bp, x->sig_alg, x->signature)) goto err; | 254 | if(!X509_signature_print(bp, x->sig_alg, x->signature)) goto err; |
255 | } | 255 | } |
256 | 256 | ||
257 | return(1); | 257 | return(1); |
258 | err: | 258 | err: |
259 | X509err(X509_F_X509_REQ_PRINT_EX,ERR_R_BUF_LIB); | 259 | X509err(X509_F_X509_REQ_PRINT_EX,ERR_R_BUF_LIB); |
260 | return(0); | 260 | return(0); |
261 | } | 261 | } |
262 | 262 | ||
263 | int X509_REQ_print(BIO *bp, X509_REQ *x) | 263 | int X509_REQ_print(BIO *bp, X509_REQ *x) |
264 | { | 264 | { |
265 | return X509_REQ_print_ex(bp, x, XN_FLAG_COMPAT, X509_FLAG_COMPAT); | 265 | return X509_REQ_print_ex(bp, x, XN_FLAG_COMPAT, X509_FLAG_COMPAT); |
266 | } | 266 | } |
diff --git a/src/lib/libssl/src/crypto/asn1/t_spki.c b/src/lib/libssl/src/crypto/asn1/t_spki.c index 079c081a81..016eb2fc2e 100644 --- a/src/lib/libssl/src/crypto/asn1/t_spki.c +++ b/src/lib/libssl/src/crypto/asn1/t_spki.c | |||
@@ -83,10 +83,10 @@ int NETSCAPE_SPKI_print(BIO *out, NETSCAPE_SPKI *spki) | |||
83 | pkey = X509_PUBKEY_get(spki->spkac->pubkey); | 83 | pkey = X509_PUBKEY_get(spki->spkac->pubkey); |
84 | if(!pkey) BIO_printf(out, " Unable to load public key\n"); | 84 | if(!pkey) BIO_printf(out, " Unable to load public key\n"); |
85 | else | 85 | else |
86 | { | 86 | { |
87 | EVP_PKEY_print_public(out, pkey, 4, NULL); | 87 | EVP_PKEY_print_public(out, pkey, 4, NULL); |
88 | EVP_PKEY_free(pkey); | 88 | EVP_PKEY_free(pkey); |
89 | } | 89 | } |
90 | chal = spki->spkac->challenge; | 90 | chal = spki->spkac->challenge; |
91 | if(chal->length) | 91 | if(chal->length) |
92 | BIO_printf(out, " Challenge String: %s\n", chal->data); | 92 | BIO_printf(out, " Challenge String: %s\n", chal->data); |
@@ -97,11 +97,11 @@ int NETSCAPE_SPKI_print(BIO *out, NETSCAPE_SPKI *spki) | |||
97 | n=spki->signature->length; | 97 | n=spki->signature->length; |
98 | s=(char *)spki->signature->data; | 98 | s=(char *)spki->signature->data; |
99 | for (i=0; i<n; i++) | 99 | for (i=0; i<n; i++) |
100 | { | 100 | { |
101 | if ((i%18) == 0) BIO_write(out,"\n ",7); | 101 | if ((i%18) == 0) BIO_write(out,"\n ",7); |
102 | BIO_printf(out,"%02x%s",(unsigned char)s[i], | 102 | BIO_printf(out,"%02x%s",(unsigned char)s[i], |
103 | ((i+1) == n)?"":":"); | 103 | ((i+1) == n)?"":":"); |
104 | } | 104 | } |
105 | BIO_write(out,"\n",1); | 105 | BIO_write(out,"\n",1); |
106 | return 1; | 106 | return 1; |
107 | } | 107 | } |
diff --git a/src/lib/libssl/src/crypto/asn1/t_x509.c b/src/lib/libssl/src/crypto/asn1/t_x509.c index 8dfda07b92..30d49cc4dd 100644 --- a/src/lib/libssl/src/crypto/asn1/t_x509.c +++ b/src/lib/libssl/src/crypto/asn1/t_x509.c | |||
@@ -76,9 +76,9 @@ | |||
76 | 76 | ||
77 | #ifndef OPENSSL_NO_FP_API | 77 | #ifndef OPENSSL_NO_FP_API |
78 | int X509_print_fp(FILE *fp, X509 *x) | 78 | int X509_print_fp(FILE *fp, X509 *x) |
79 | { | 79 | { |
80 | return X509_print_ex_fp(fp, x, XN_FLAG_COMPAT, X509_FLAG_COMPAT); | 80 | return X509_print_ex_fp(fp, x, XN_FLAG_COMPAT, X509_FLAG_COMPAT); |
81 | } | 81 | } |
82 | 82 | ||
83 | int X509_print_ex_fp(FILE *fp, X509 *x, unsigned long nmflag, unsigned long cflag) | 83 | int X509_print_ex_fp(FILE *fp, X509 *x, unsigned long nmflag, unsigned long cflag) |
84 | { | 84 | { |
@@ -86,10 +86,10 @@ int X509_print_ex_fp(FILE *fp, X509 *x, unsigned long nmflag, unsigned long cfla | |||
86 | int ret; | 86 | int ret; |
87 | 87 | ||
88 | if ((b=BIO_new(BIO_s_file())) == NULL) | 88 | if ((b=BIO_new(BIO_s_file())) == NULL) |
89 | { | 89 | { |
90 | X509err(X509_F_X509_PRINT_EX_FP,ERR_R_BUF_LIB); | 90 | X509err(X509_F_X509_PRINT_EX_FP,ERR_R_BUF_LIB); |
91 | return(0); | 91 | return(0); |
92 | } | 92 | } |
93 | BIO_set_fp(b,fp,BIO_NOCLOSE); | 93 | BIO_set_fp(b,fp,BIO_NOCLOSE); |
94 | ret=X509_print_ex(b, x, nmflag, cflag); | 94 | ret=X509_print_ex(b, x, nmflag, cflag); |
95 | BIO_free(b); | 95 | BIO_free(b); |
@@ -103,7 +103,7 @@ int X509_print(BIO *bp, X509 *x) | |||
103 | } | 103 | } |
104 | 104 | ||
105 | int X509_print_ex(BIO *bp, X509 *x, unsigned long nmflags, unsigned long cflag) | 105 | int X509_print_ex(BIO *bp, X509 *x, unsigned long nmflags, unsigned long cflag) |
106 | { | 106 | { |
107 | long l; | 107 | long l; |
108 | int ret=0,i; | 108 | int ret=0,i; |
109 | char *m=NULL,mlch = ' '; | 109 | char *m=NULL,mlch = ' '; |
@@ -123,51 +123,51 @@ int X509_print_ex(BIO *bp, X509 *x, unsigned long nmflags, unsigned long cflag) | |||
123 | 123 | ||
124 | ci=x->cert_info; | 124 | ci=x->cert_info; |
125 | if(!(cflag & X509_FLAG_NO_HEADER)) | 125 | if(!(cflag & X509_FLAG_NO_HEADER)) |
126 | { | 126 | { |
127 | if (BIO_write(bp,"Certificate:\n",13) <= 0) goto err; | 127 | if (BIO_write(bp,"Certificate:\n",13) <= 0) goto err; |
128 | if (BIO_write(bp," Data:\n",10) <= 0) goto err; | 128 | if (BIO_write(bp," Data:\n",10) <= 0) goto err; |
129 | } | 129 | } |
130 | if(!(cflag & X509_FLAG_NO_VERSION)) | 130 | if(!(cflag & X509_FLAG_NO_VERSION)) |
131 | { | 131 | { |
132 | l=X509_get_version(x); | 132 | l=X509_get_version(x); |
133 | if (BIO_printf(bp,"%8sVersion: %lu (0x%lx)\n","",l+1,l) <= 0) goto err; | 133 | if (BIO_printf(bp,"%8sVersion: %lu (0x%lx)\n","",l+1,l) <= 0) goto err; |
134 | } | 134 | } |
135 | if(!(cflag & X509_FLAG_NO_SERIAL)) | 135 | if(!(cflag & X509_FLAG_NO_SERIAL)) |
136 | { | 136 | { |
137 | 137 | ||
138 | if (BIO_write(bp," Serial Number:",22) <= 0) goto err; | 138 | if (BIO_write(bp," Serial Number:",22) <= 0) goto err; |
139 | 139 | ||
140 | bs=X509_get_serialNumber(x); | 140 | bs=X509_get_serialNumber(x); |
141 | if (bs->length <= (int)sizeof(long)) | 141 | if (bs->length <= (int)sizeof(long)) |
142 | { | 142 | { |
143 | l=ASN1_INTEGER_get(bs); | 143 | l=ASN1_INTEGER_get(bs); |
144 | if (bs->type == V_ASN1_NEG_INTEGER) | 144 | if (bs->type == V_ASN1_NEG_INTEGER) |
145 | { | 145 | { |
146 | l= -l; | 146 | l= -l; |
147 | neg="-"; | 147 | neg="-"; |
148 | } | 148 | } |
149 | else | 149 | else |
150 | neg=""; | 150 | neg=""; |
151 | if (BIO_printf(bp," %s%lu (%s0x%lx)\n",neg,l,neg,l) <= 0) | 151 | if (BIO_printf(bp," %s%lu (%s0x%lx)\n",neg,l,neg,l) <= 0) |
152 | goto err; | 152 | goto err; |
153 | } | 153 | } |
154 | else | 154 | else |
155 | { | 155 | { |
156 | neg=(bs->type == V_ASN1_NEG_INTEGER)?" (Negative)":""; | 156 | neg=(bs->type == V_ASN1_NEG_INTEGER)?" (Negative)":""; |
157 | if (BIO_printf(bp,"\n%12s%s","",neg) <= 0) goto err; | 157 | if (BIO_printf(bp,"\n%12s%s","",neg) <= 0) goto err; |
158 | 158 | ||
159 | for (i=0; i<bs->length; i++) | 159 | for (i=0; i<bs->length; i++) |
160 | { | 160 | { |
161 | if (BIO_printf(bp,"%02x%c",bs->data[i], | 161 | if (BIO_printf(bp,"%02x%c",bs->data[i], |
162 | ((i+1 == bs->length)?'\n':':')) <= 0) | 162 | ((i+1 == bs->length)?'\n':':')) <= 0) |
163 | goto err; | 163 | goto err; |
164 | } | ||
165 | } | 164 | } |
166 | |||
167 | } | 165 | } |
168 | 166 | ||
167 | } | ||
168 | |||
169 | if(!(cflag & X509_FLAG_NO_SIGNAME)) | 169 | if(!(cflag & X509_FLAG_NO_SIGNAME)) |
170 | { | 170 | { |
171 | if(X509_signature_print(bp, x->sig_alg, NULL) <= 0) | 171 | if(X509_signature_print(bp, x->sig_alg, NULL) <= 0) |
172 | goto err; | 172 | goto err; |
173 | #if 0 | 173 | #if 0 |
@@ -178,31 +178,31 @@ int X509_print_ex(BIO *bp, X509 *x, unsigned long nmflags, unsigned long cflag) | |||
178 | if (BIO_puts(bp, "\n") <= 0) | 178 | if (BIO_puts(bp, "\n") <= 0) |
179 | goto err; | 179 | goto err; |
180 | #endif | 180 | #endif |
181 | } | 181 | } |
182 | 182 | ||
183 | if(!(cflag & X509_FLAG_NO_ISSUER)) | 183 | if(!(cflag & X509_FLAG_NO_ISSUER)) |
184 | { | 184 | { |
185 | if (BIO_printf(bp," Issuer:%c",mlch) <= 0) goto err; | 185 | if (BIO_printf(bp," Issuer:%c",mlch) <= 0) goto err; |
186 | if (X509_NAME_print_ex(bp,X509_get_issuer_name(x),nmindent, nmflags) < 0) goto err; | 186 | if (X509_NAME_print_ex(bp,X509_get_issuer_name(x),nmindent, nmflags) < 0) goto err; |
187 | if (BIO_write(bp,"\n",1) <= 0) goto err; | 187 | if (BIO_write(bp,"\n",1) <= 0) goto err; |
188 | } | 188 | } |
189 | if(!(cflag & X509_FLAG_NO_VALIDITY)) | 189 | if(!(cflag & X509_FLAG_NO_VALIDITY)) |
190 | { | 190 | { |
191 | if (BIO_write(bp," Validity\n",17) <= 0) goto err; | 191 | if (BIO_write(bp," Validity\n",17) <= 0) goto err; |
192 | if (BIO_write(bp," Not Before: ",24) <= 0) goto err; | 192 | if (BIO_write(bp," Not Before: ",24) <= 0) goto err; |
193 | if (!ASN1_TIME_print(bp,X509_get_notBefore(x))) goto err; | 193 | if (!ASN1_TIME_print(bp,X509_get_notBefore(x))) goto err; |
194 | if (BIO_write(bp,"\n Not After : ",25) <= 0) goto err; | 194 | if (BIO_write(bp,"\n Not After : ",25) <= 0) goto err; |
195 | if (!ASN1_TIME_print(bp,X509_get_notAfter(x))) goto err; | 195 | if (!ASN1_TIME_print(bp,X509_get_notAfter(x))) goto err; |
196 | if (BIO_write(bp,"\n",1) <= 0) goto err; | 196 | if (BIO_write(bp,"\n",1) <= 0) goto err; |
197 | } | 197 | } |
198 | if(!(cflag & X509_FLAG_NO_SUBJECT)) | 198 | if(!(cflag & X509_FLAG_NO_SUBJECT)) |
199 | { | 199 | { |
200 | if (BIO_printf(bp," Subject:%c",mlch) <= 0) goto err; | 200 | if (BIO_printf(bp," Subject:%c",mlch) <= 0) goto err; |
201 | if (X509_NAME_print_ex(bp,X509_get_subject_name(x),nmindent, nmflags) < 0) goto err; | 201 | if (X509_NAME_print_ex(bp,X509_get_subject_name(x),nmindent, nmflags) < 0) goto err; |
202 | if (BIO_write(bp,"\n",1) <= 0) goto err; | 202 | if (BIO_write(bp,"\n",1) <= 0) goto err; |
203 | } | 203 | } |
204 | if(!(cflag & X509_FLAG_NO_PUBKEY)) | 204 | if(!(cflag & X509_FLAG_NO_PUBKEY)) |
205 | { | 205 | { |
206 | if (BIO_write(bp," Subject Public Key Info:\n",33) <= 0) | 206 | if (BIO_write(bp," Subject Public Key Info:\n",33) <= 0) |
207 | goto err; | 207 | goto err; |
208 | if (BIO_printf(bp,"%12sPublic Key Algorithm: ","") <= 0) | 208 | if (BIO_printf(bp,"%12sPublic Key Algorithm: ","") <= 0) |
@@ -214,37 +214,37 @@ int X509_print_ex(BIO *bp, X509 *x, unsigned long nmflags, unsigned long cflag) | |||
214 | 214 | ||
215 | pkey=X509_get_pubkey(x); | 215 | pkey=X509_get_pubkey(x); |
216 | if (pkey == NULL) | 216 | if (pkey == NULL) |
217 | { | 217 | { |
218 | BIO_printf(bp,"%12sUnable to load Public Key\n",""); | 218 | BIO_printf(bp,"%12sUnable to load Public Key\n",""); |
219 | ERR_print_errors(bp); | 219 | ERR_print_errors(bp); |
220 | } | 220 | } |
221 | else | 221 | else |
222 | { | 222 | { |
223 | EVP_PKEY_print_public(bp, pkey, 16, NULL); | 223 | EVP_PKEY_print_public(bp, pkey, 16, NULL); |
224 | EVP_PKEY_free(pkey); | 224 | EVP_PKEY_free(pkey); |
225 | } | ||
226 | } | 225 | } |
226 | } | ||
227 | 227 | ||
228 | if (!(cflag & X509_FLAG_NO_EXTENSIONS)) | 228 | if (!(cflag & X509_FLAG_NO_EXTENSIONS)) |
229 | X509V3_extensions_print(bp, "X509v3 extensions", | 229 | X509V3_extensions_print(bp, "X509v3 extensions", |
230 | ci->extensions, cflag, 8); | 230 | ci->extensions, cflag, 8); |
231 | 231 | ||
232 | if(!(cflag & X509_FLAG_NO_SIGDUMP)) | 232 | if(!(cflag & X509_FLAG_NO_SIGDUMP)) |
233 | { | 233 | { |
234 | if(X509_signature_print(bp, x->sig_alg, x->signature) <= 0) goto err; | 234 | if(X509_signature_print(bp, x->sig_alg, x->signature) <= 0) goto err; |
235 | } | 235 | } |
236 | if(!(cflag & X509_FLAG_NO_AUX)) | 236 | if(!(cflag & X509_FLAG_NO_AUX)) |
237 | { | 237 | { |
238 | if (!X509_CERT_AUX_print(bp, x->aux, 0)) goto err; | 238 | if (!X509_CERT_AUX_print(bp, x->aux, 0)) goto err; |
239 | } | 239 | } |
240 | ret=1; | 240 | ret=1; |
241 | err: | 241 | err: |
242 | if (m != NULL) free(m); | 242 | if (m != NULL) free(m); |
243 | return(ret); | 243 | return(ret); |
244 | } | 244 | } |
245 | 245 | ||
246 | int X509_ocspid_print (BIO *bp, X509 *x) | 246 | int X509_ocspid_print (BIO *bp, X509 *x) |
247 | { | 247 | { |
248 | unsigned char *der=NULL ; | 248 | unsigned char *der=NULL ; |
249 | unsigned char *dertmp; | 249 | unsigned char *dertmp; |
250 | int derlen; | 250 | int derlen; |
@@ -263,9 +263,9 @@ int X509_ocspid_print (BIO *bp, X509 *x) | |||
263 | if (!EVP_Digest(der, derlen, SHA1md, NULL, EVP_sha1(), NULL)) | 263 | if (!EVP_Digest(der, derlen, SHA1md, NULL, EVP_sha1(), NULL)) |
264 | goto err; | 264 | goto err; |
265 | for (i=0; i < SHA_DIGEST_LENGTH; i++) | 265 | for (i=0; i < SHA_DIGEST_LENGTH; i++) |
266 | { | 266 | { |
267 | if (BIO_printf(bp,"%02X",SHA1md[i]) <= 0) goto err; | 267 | if (BIO_printf(bp,"%02X",SHA1md[i]) <= 0) goto err; |
268 | } | 268 | } |
269 | free (der); | 269 | free (der); |
270 | der=NULL; | 270 | der=NULL; |
271 | 271 | ||
@@ -279,17 +279,17 @@ int X509_ocspid_print (BIO *bp, X509 *x) | |||
279 | SHA1md, NULL, EVP_sha1(), NULL)) | 279 | SHA1md, NULL, EVP_sha1(), NULL)) |
280 | goto err; | 280 | goto err; |
281 | for (i=0; i < SHA_DIGEST_LENGTH; i++) | 281 | for (i=0; i < SHA_DIGEST_LENGTH; i++) |
282 | { | 282 | { |
283 | if (BIO_printf(bp,"%02X",SHA1md[i]) <= 0) | 283 | if (BIO_printf(bp,"%02X",SHA1md[i]) <= 0) |
284 | goto err; | 284 | goto err; |
285 | } | 285 | } |
286 | BIO_printf(bp,"\n"); | 286 | BIO_printf(bp,"\n"); |
287 | 287 | ||
288 | return (1); | 288 | return (1); |
289 | err: | 289 | err: |
290 | if (der != NULL) free(der); | 290 | if (der != NULL) free(der); |
291 | return(0); | 291 | return(0); |
292 | } | 292 | } |
293 | 293 | ||
294 | int X509_signature_dump(BIO *bp, const ASN1_STRING *sig, int indent) | 294 | int X509_signature_dump(BIO *bp, const ASN1_STRING *sig, int indent) |
295 | { | 295 | { |
@@ -299,15 +299,15 @@ int X509_signature_dump(BIO *bp, const ASN1_STRING *sig, int indent) | |||
299 | n=sig->length; | 299 | n=sig->length; |
300 | s=sig->data; | 300 | s=sig->data; |
301 | for (i=0; i<n; i++) | 301 | for (i=0; i<n; i++) |
302 | { | 302 | { |
303 | if ((i%18) == 0) | 303 | if ((i%18) == 0) |
304 | { | 304 | { |
305 | if (BIO_write(bp,"\n",1) <= 0) return 0; | 305 | if (BIO_write(bp,"\n",1) <= 0) return 0; |
306 | if (BIO_indent(bp, indent, indent) <= 0) return 0; | 306 | if (BIO_indent(bp, indent, indent) <= 0) return 0; |
307 | } | 307 | } |
308 | if (BIO_printf(bp,"%02x%s",s[i], | 308 | if (BIO_printf(bp,"%02x%s",s[i], |
309 | ((i+1) == n)?"":":") <= 0) return 0; | 309 | ((i+1) == n)?"":":") <= 0) return 0; |
310 | } | 310 | } |
311 | if (BIO_write(bp,"\n",1) != 1) return 0; | 311 | if (BIO_write(bp,"\n",1) != 1) return 0; |
312 | 312 | ||
313 | return 1; | 313 | return 1; |
@@ -321,16 +321,16 @@ int X509_signature_print(BIO *bp, X509_ALGOR *sigalg, ASN1_STRING *sig) | |||
321 | 321 | ||
322 | sig_nid = OBJ_obj2nid(sigalg->algorithm); | 322 | sig_nid = OBJ_obj2nid(sigalg->algorithm); |
323 | if (sig_nid != NID_undef) | 323 | if (sig_nid != NID_undef) |
324 | { | 324 | { |
325 | int pkey_nid, dig_nid; | 325 | int pkey_nid, dig_nid; |
326 | const EVP_PKEY_ASN1_METHOD *ameth; | 326 | const EVP_PKEY_ASN1_METHOD *ameth; |
327 | if (OBJ_find_sigid_algs(sig_nid, &dig_nid, &pkey_nid)) | 327 | if (OBJ_find_sigid_algs(sig_nid, &dig_nid, &pkey_nid)) |
328 | { | 328 | { |
329 | ameth = EVP_PKEY_asn1_find(NULL, pkey_nid); | 329 | ameth = EVP_PKEY_asn1_find(NULL, pkey_nid); |
330 | if (ameth && ameth->sig_print) | 330 | if (ameth && ameth->sig_print) |
331 | return ameth->sig_print(bp, sigalg, sig, 9, 0); | 331 | return ameth->sig_print(bp, sigalg, sig, 9, 0); |
332 | } | ||
333 | } | 332 | } |
333 | } | ||
334 | if (sig) | 334 | if (sig) |
335 | return X509_signature_dump(bp, sig, 9); | 335 | return X509_signature_dump(bp, sig, 9); |
336 | else if (BIO_puts(bp, "\n") <= 0) | 336 | else if (BIO_puts(bp, "\n") <= 0) |
@@ -339,7 +339,7 @@ int X509_signature_print(BIO *bp, X509_ALGOR *sigalg, ASN1_STRING *sig) | |||
339 | } | 339 | } |
340 | 340 | ||
341 | int ASN1_STRING_print(BIO *bp, const ASN1_STRING *v) | 341 | int ASN1_STRING_print(BIO *bp, const ASN1_STRING *v) |
342 | { | 342 | { |
343 | int i,n; | 343 | int i,n; |
344 | char buf[80]; | 344 | char buf[80]; |
345 | const char *p; | 345 | const char *p; |
@@ -348,7 +348,7 @@ int ASN1_STRING_print(BIO *bp, const ASN1_STRING *v) | |||
348 | n=0; | 348 | n=0; |
349 | p=(const char *)v->data; | 349 | p=(const char *)v->data; |
350 | for (i=0; i<v->length; i++) | 350 | for (i=0; i<v->length; i++) |
351 | { | 351 | { |
352 | if ((p[i] > '~') || ((p[i] < ' ') && | 352 | if ((p[i] > '~') || ((p[i] < ' ') && |
353 | (p[i] != '\n') && (p[i] != '\r'))) | 353 | (p[i] != '\n') && (p[i] != '\r'))) |
354 | buf[n]='.'; | 354 | buf[n]='.'; |
@@ -356,17 +356,17 @@ int ASN1_STRING_print(BIO *bp, const ASN1_STRING *v) | |||
356 | buf[n]=p[i]; | 356 | buf[n]=p[i]; |
357 | n++; | 357 | n++; |
358 | if (n >= 80) | 358 | if (n >= 80) |
359 | { | 359 | { |
360 | if (BIO_write(bp,buf,n) <= 0) | 360 | if (BIO_write(bp,buf,n) <= 0) |
361 | return(0); | 361 | return(0); |
362 | n=0; | 362 | n=0; |
363 | } | ||
364 | } | 363 | } |
364 | } | ||
365 | if (n > 0) | 365 | if (n > 0) |
366 | if (BIO_write(bp,buf,n) <= 0) | 366 | if (BIO_write(bp,buf,n) <= 0) |
367 | return(0); | 367 | return(0); |
368 | return(1); | 368 | return(1); |
369 | } | 369 | } |
370 | 370 | ||
371 | int ASN1_TIME_print(BIO *bp, const ASN1_TIME *tm) | 371 | int ASN1_TIME_print(BIO *bp, const ASN1_TIME *tm) |
372 | { | 372 | { |
@@ -384,7 +384,7 @@ static const char *mon[12]= | |||
384 | }; | 384 | }; |
385 | 385 | ||
386 | int ASN1_GENERALIZEDTIME_print(BIO *bp, const ASN1_GENERALIZEDTIME *tm) | 386 | int ASN1_GENERALIZEDTIME_print(BIO *bp, const ASN1_GENERALIZEDTIME *tm) |
387 | { | 387 | { |
388 | char *v; | 388 | char *v; |
389 | int gmt=0; | 389 | int gmt=0; |
390 | int i; | 390 | int i; |
@@ -408,18 +408,18 @@ int ASN1_GENERALIZEDTIME_print(BIO *bp, const ASN1_GENERALIZEDTIME *tm) | |||
408 | if (tm->length >= 14 && | 408 | if (tm->length >= 14 && |
409 | (v[12] >= '0') && (v[12] <= '9') && | 409 | (v[12] >= '0') && (v[12] <= '9') && |
410 | (v[13] >= '0') && (v[13] <= '9')) | 410 | (v[13] >= '0') && (v[13] <= '9')) |
411 | { | 411 | { |
412 | s= (v[12]-'0')*10+(v[13]-'0'); | 412 | s= (v[12]-'0')*10+(v[13]-'0'); |
413 | /* Check for fractions of seconds. */ | 413 | /* Check for fractions of seconds. */ |
414 | if (tm->length >= 15 && v[14] == '.') | 414 | if (tm->length >= 15 && v[14] == '.') |
415 | { | 415 | { |
416 | int l = tm->length; | 416 | int l = tm->length; |
417 | f = &v[14]; /* The decimal point. */ | 417 | f = &v[14]; /* The decimal point. */ |
418 | f_len = 1; | 418 | f_len = 1; |
419 | while (14 + f_len < l && f[f_len] >= '0' && f[f_len] <= '9') | 419 | while (14 + f_len < l && f[f_len] >= '0' && f[f_len] <= '9') |
420 | ++f_len; | 420 | ++f_len; |
421 | } | ||
422 | } | 421 | } |
422 | } | ||
423 | 423 | ||
424 | if (BIO_printf(bp,"%s %2d %02d:%02d:%02d%.*s %d%s", | 424 | if (BIO_printf(bp,"%s %2d %02d:%02d:%02d%.*s %d%s", |
425 | mon[M-1],d,h,m,s,f_len,f,y,(gmt)?" GMT":"") <= 0) | 425 | mon[M-1],d,h,m,s,f_len,f,y,(gmt)?" GMT":"") <= 0) |
@@ -429,10 +429,10 @@ int ASN1_GENERALIZEDTIME_print(BIO *bp, const ASN1_GENERALIZEDTIME *tm) | |||
429 | err: | 429 | err: |
430 | BIO_write(bp,"Bad time value",14); | 430 | BIO_write(bp,"Bad time value",14); |
431 | return(0); | 431 | return(0); |
432 | } | 432 | } |
433 | 433 | ||
434 | int ASN1_UTCTIME_print(BIO *bp, const ASN1_UTCTIME *tm) | 434 | int ASN1_UTCTIME_print(BIO *bp, const ASN1_UTCTIME *tm) |
435 | { | 435 | { |
436 | const char *v; | 436 | const char *v; |
437 | int gmt=0; | 437 | int gmt=0; |
438 | int i; | 438 | int i; |
@@ -465,10 +465,10 @@ int ASN1_UTCTIME_print(BIO *bp, const ASN1_UTCTIME *tm) | |||
465 | err: | 465 | err: |
466 | BIO_write(bp,"Bad time value",14); | 466 | BIO_write(bp,"Bad time value",14); |
467 | return(0); | 467 | return(0); |
468 | } | 468 | } |
469 | 469 | ||
470 | int X509_NAME_print(BIO *bp, X509_NAME *name, int obase) | 470 | int X509_NAME_print(BIO *bp, X509_NAME *name, int obase) |
471 | { | 471 | { |
472 | char *s,*c,*b; | 472 | char *s,*c,*b; |
473 | int ret=0,l,i; | 473 | int ret=0,l,i; |
474 | 474 | ||
@@ -476,15 +476,15 @@ int X509_NAME_print(BIO *bp, X509_NAME *name, int obase) | |||
476 | 476 | ||
477 | b=X509_NAME_oneline(name,NULL,0); | 477 | b=X509_NAME_oneline(name,NULL,0); |
478 | if (!*b) | 478 | if (!*b) |
479 | { | 479 | { |
480 | free(b); | 480 | free(b); |
481 | return 1; | 481 | return 1; |
482 | } | 482 | } |
483 | s=b+1; /* skip the first slash */ | 483 | s=b+1; /* skip the first slash */ |
484 | 484 | ||
485 | c=s; | 485 | c=s; |
486 | for (;;) | 486 | for (;;) |
487 | { | 487 | { |
488 | if ( ((*s == '/') && | 488 | if ( ((*s == '/') && |
489 | ((s[1] >= 'A') && (s[1] <= 'Z') && ( | 489 | ((s[1] >= 'A') && (s[1] <= 'Z') && ( |
490 | (s[2] == '=') || | 490 | (s[2] == '=') || |
@@ -492,27 +492,27 @@ int X509_NAME_print(BIO *bp, X509_NAME *name, int obase) | |||
492 | (s[3] == '=')) | 492 | (s[3] == '=')) |
493 | ))) || | 493 | ))) || |
494 | (*s == '\0')) | 494 | (*s == '\0')) |
495 | { | 495 | { |
496 | i=s-c; | 496 | i=s-c; |
497 | if (BIO_write(bp,c,i) != i) goto err; | 497 | if (BIO_write(bp,c,i) != i) goto err; |
498 | c=s+1; /* skip following slash */ | 498 | c=s+1; /* skip following slash */ |
499 | if (*s != '\0') | 499 | if (*s != '\0') |
500 | { | 500 | { |
501 | if (BIO_write(bp,", ",2) != 2) goto err; | 501 | if (BIO_write(bp,", ",2) != 2) goto err; |
502 | } | ||
503 | l--; | ||
504 | } | 502 | } |
503 | l--; | ||
504 | } | ||
505 | if (*s == '\0') break; | 505 | if (*s == '\0') break; |
506 | s++; | 506 | s++; |
507 | l--; | 507 | l--; |
508 | } | 508 | } |
509 | 509 | ||
510 | ret=1; | 510 | ret=1; |
511 | if (0) | 511 | if (0) |
512 | { | 512 | { |
513 | err: | 513 | err: |
514 | X509err(X509_F_X509_NAME_PRINT,ERR_R_BUF_LIB); | 514 | X509err(X509_F_X509_NAME_PRINT,ERR_R_BUF_LIB); |
515 | } | 515 | } |
516 | free(b); | 516 | free(b); |
517 | return(ret); | 517 | return(ret); |
518 | } | 518 | } |
diff --git a/src/lib/libssl/src/crypto/asn1/tasn_dec.c b/src/lib/libssl/src/crypto/asn1/tasn_dec.c index c594db9140..0df42a4a93 100644 --- a/src/lib/libssl/src/crypto/asn1/tasn_dec.c +++ b/src/lib/libssl/src/crypto/asn1/tasn_dec.c | |||
@@ -103,13 +103,13 @@ B_ASN1_T61STRING,B_ASN1_VIDEOTEXSTRING,B_ASN1_IA5STRING, /* tags 20-22 */ | |||
103 | B_ASN1_UTCTIME, B_ASN1_GENERALIZEDTIME, /* tags 23-24 */ | 103 | B_ASN1_UTCTIME, B_ASN1_GENERALIZEDTIME, /* tags 23-24 */ |
104 | B_ASN1_GRAPHICSTRING,B_ASN1_ISO64STRING,B_ASN1_GENERALSTRING, /* tags 25-27 */ | 104 | B_ASN1_GRAPHICSTRING,B_ASN1_ISO64STRING,B_ASN1_GENERALSTRING, /* tags 25-27 */ |
105 | B_ASN1_UNIVERSALSTRING,B_ASN1_UNKNOWN,B_ASN1_BMPSTRING,B_ASN1_UNKNOWN, /* tags 28-31 */ | 105 | B_ASN1_UNIVERSALSTRING,B_ASN1_UNKNOWN,B_ASN1_BMPSTRING,B_ASN1_UNKNOWN, /* tags 28-31 */ |
106 | }; | 106 | }; |
107 | 107 | ||
108 | unsigned long ASN1_tag2bit(int tag) | 108 | unsigned long ASN1_tag2bit(int tag) |
109 | { | 109 | { |
110 | if ((tag < 0) || (tag > 30)) return 0; | 110 | if ((tag < 0) || (tag > 30)) return 0; |
111 | return tag2bit[tag]; | 111 | return tag2bit[tag]; |
112 | } | 112 | } |
113 | 113 | ||
114 | /* Macro to initialize and invalidate the cache */ | 114 | /* Macro to initialize and invalidate the cache */ |
115 | 115 | ||
@@ -127,7 +127,7 @@ unsigned long ASN1_tag2bit(int tag) | |||
127 | 127 | ||
128 | ASN1_VALUE *ASN1_item_d2i(ASN1_VALUE **pval, | 128 | ASN1_VALUE *ASN1_item_d2i(ASN1_VALUE **pval, |
129 | const unsigned char **in, long len, const ASN1_ITEM *it) | 129 | const unsigned char **in, long len, const ASN1_ITEM *it) |
130 | { | 130 | { |
131 | ASN1_TLC c; | 131 | ASN1_TLC c; |
132 | ASN1_VALUE *ptmpval = NULL; | 132 | ASN1_VALUE *ptmpval = NULL; |
133 | if (!pval) | 133 | if (!pval) |
@@ -136,15 +136,15 @@ ASN1_VALUE *ASN1_item_d2i(ASN1_VALUE **pval, | |||
136 | if (ASN1_item_ex_d2i(pval, in, len, it, -1, 0, 0, &c) > 0) | 136 | if (ASN1_item_ex_d2i(pval, in, len, it, -1, 0, 0, &c) > 0) |
137 | return *pval; | 137 | return *pval; |
138 | return NULL; | 138 | return NULL; |
139 | } | 139 | } |
140 | 140 | ||
141 | int ASN1_template_d2i(ASN1_VALUE **pval, | 141 | int ASN1_template_d2i(ASN1_VALUE **pval, |
142 | const unsigned char **in, long len, const ASN1_TEMPLATE *tt) | 142 | const unsigned char **in, long len, const ASN1_TEMPLATE *tt) |
143 | { | 143 | { |
144 | ASN1_TLC c; | 144 | ASN1_TLC c; |
145 | asn1_tlc_clear_nc(&c); | 145 | asn1_tlc_clear_nc(&c); |
146 | return asn1_template_ex_d2i(pval, in, len, tt, 0, &c); | 146 | return asn1_template_ex_d2i(pval, in, len, tt, 0, &c); |
147 | } | 147 | } |
148 | 148 | ||
149 | 149 | ||
150 | /* Decode an item, taking care of IMPLICIT tagging, if any. | 150 | /* Decode an item, taking care of IMPLICIT tagging, if any. |
@@ -154,7 +154,7 @@ int ASN1_template_d2i(ASN1_VALUE **pval, | |||
154 | int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, | 154 | int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, |
155 | const ASN1_ITEM *it, | 155 | const ASN1_ITEM *it, |
156 | int tag, int aclass, char opt, ASN1_TLC *ctx) | 156 | int tag, int aclass, char opt, ASN1_TLC *ctx) |
157 | { | 157 | { |
158 | const ASN1_TEMPLATE *tt, *errtt = NULL; | 158 | const ASN1_TEMPLATE *tt, *errtt = NULL; |
159 | const ASN1_COMPAT_FUNCS *cf; | 159 | const ASN1_COMPAT_FUNCS *cf; |
160 | const ASN1_EXTERN_FUNCS *ef; | 160 | const ASN1_EXTERN_FUNCS *ef; |
@@ -176,10 +176,10 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, | |||
176 | else asn1_cb = 0; | 176 | else asn1_cb = 0; |
177 | 177 | ||
178 | switch(it->itype) | 178 | switch(it->itype) |
179 | { | 179 | { |
180 | case ASN1_ITYPE_PRIMITIVE: | 180 | case ASN1_ITYPE_PRIMITIVE: |
181 | if (it->templates) | 181 | if (it->templates) |
182 | { | 182 | { |
183 | /* tagging or OPTIONAL is currently illegal on an item | 183 | /* tagging or OPTIONAL is currently illegal on an item |
184 | * template because the flags can't get passed down. | 184 | * template because the flags can't get passed down. |
185 | * In practice this isn't a problem: we include the | 185 | * In practice this isn't a problem: we include the |
@@ -187,14 +187,14 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, | |||
187 | * template itself. | 187 | * template itself. |
188 | */ | 188 | */ |
189 | if ((tag != -1) || opt) | 189 | if ((tag != -1) || opt) |
190 | { | 190 | { |
191 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, | 191 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, |
192 | ASN1_R_ILLEGAL_OPTIONS_ON_ITEM_TEMPLATE); | 192 | ASN1_R_ILLEGAL_OPTIONS_ON_ITEM_TEMPLATE); |
193 | goto err; | 193 | goto err; |
194 | } | 194 | } |
195 | return asn1_template_ex_d2i(pval, in, len, | 195 | return asn1_template_ex_d2i(pval, in, len, |
196 | it->templates, opt, ctx); | 196 | it->templates, opt, ctx); |
197 | } | 197 | } |
198 | return asn1_d2i_ex_primitive(pval, in, len, it, | 198 | return asn1_d2i_ex_primitive(pval, in, len, it, |
199 | tag, aclass, opt, ctx); | 199 | tag, aclass, opt, ctx); |
200 | break; | 200 | break; |
@@ -205,31 +205,31 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, | |||
205 | ret = asn1_check_tlen(NULL, &otag, &oclass, NULL, NULL, | 205 | ret = asn1_check_tlen(NULL, &otag, &oclass, NULL, NULL, |
206 | &p, len, -1, 0, 1, ctx); | 206 | &p, len, -1, 0, 1, ctx); |
207 | if (!ret) | 207 | if (!ret) |
208 | { | 208 | { |
209 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, | 209 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, |
210 | ERR_R_NESTED_ASN1_ERROR); | 210 | ERR_R_NESTED_ASN1_ERROR); |
211 | goto err; | 211 | goto err; |
212 | } | 212 | } |
213 | 213 | ||
214 | /* Must be UNIVERSAL class */ | 214 | /* Must be UNIVERSAL class */ |
215 | if (oclass != V_ASN1_UNIVERSAL) | 215 | if (oclass != V_ASN1_UNIVERSAL) |
216 | { | 216 | { |
217 | /* If OPTIONAL, assume this is OK */ | 217 | /* If OPTIONAL, assume this is OK */ |
218 | if (opt) return -1; | 218 | if (opt) return -1; |
219 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, | 219 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, |
220 | ASN1_R_MSTRING_NOT_UNIVERSAL); | 220 | ASN1_R_MSTRING_NOT_UNIVERSAL); |
221 | goto err; | 221 | goto err; |
222 | } | 222 | } |
223 | /* Check tag matches bit map */ | 223 | /* Check tag matches bit map */ |
224 | if (!(ASN1_tag2bit(otag) & it->utype)) | 224 | if (!(ASN1_tag2bit(otag) & it->utype)) |
225 | { | 225 | { |
226 | /* If OPTIONAL, assume this is OK */ | 226 | /* If OPTIONAL, assume this is OK */ |
227 | if (opt) | 227 | if (opt) |
228 | return -1; | 228 | return -1; |
229 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, | 229 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, |
230 | ASN1_R_MSTRING_WRONG_TAG); | 230 | ASN1_R_MSTRING_WRONG_TAG); |
231 | goto err; | 231 | goto err; |
232 | } | 232 | } |
233 | return asn1_d2i_ex_primitive(pval, in, len, | 233 | return asn1_d2i_ex_primitive(pval, in, len, |
234 | it, otag, 0, 0, ctx); | 234 | it, otag, 0, 0, ctx); |
235 | 235 | ||
@@ -245,7 +245,7 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, | |||
245 | 245 | ||
246 | /* If OPTIONAL see if it is there */ | 246 | /* If OPTIONAL see if it is there */ |
247 | if (opt) | 247 | if (opt) |
248 | { | 248 | { |
249 | int exptag; | 249 | int exptag; |
250 | p = *in; | 250 | p = *in; |
251 | if (tag == -1) | 251 | if (tag == -1) |
@@ -257,14 +257,14 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, | |||
257 | ret = asn1_check_tlen(NULL, NULL, NULL, NULL, NULL, | 257 | ret = asn1_check_tlen(NULL, NULL, NULL, NULL, NULL, |
258 | &p, len, exptag, aclass, 1, ctx); | 258 | &p, len, exptag, aclass, 1, ctx); |
259 | if (!ret) | 259 | if (!ret) |
260 | { | 260 | { |
261 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, | 261 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, |
262 | ERR_R_NESTED_ASN1_ERROR); | 262 | ERR_R_NESTED_ASN1_ERROR); |
263 | goto err; | 263 | goto err; |
264 | } | 264 | } |
265 | if (ret == -1) | 265 | if (ret == -1) |
266 | return -1; | 266 | return -1; |
267 | } | 267 | } |
268 | 268 | ||
269 | /* This is the old style evil hack IMPLICIT handling: | 269 | /* This is the old style evil hack IMPLICIT handling: |
270 | * since the underlying code is expecting a tag and | 270 | * since the underlying code is expecting a tag and |
@@ -282,18 +282,18 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, | |||
282 | */ | 282 | */ |
283 | 283 | ||
284 | if (tag != -1) | 284 | if (tag != -1) |
285 | { | 285 | { |
286 | wp = *(unsigned char **)in; | 286 | wp = *(unsigned char **)in; |
287 | imphack = *wp; | 287 | imphack = *wp; |
288 | if (p == NULL) | 288 | if (p == NULL) |
289 | { | 289 | { |
290 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, | 290 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, |
291 | ERR_R_NESTED_ASN1_ERROR); | 291 | ERR_R_NESTED_ASN1_ERROR); |
292 | goto err; | 292 | goto err; |
293 | } | 293 | } |
294 | *wp = (unsigned char)((*p & V_ASN1_CONSTRUCTED) | 294 | *wp = (unsigned char)((*p & V_ASN1_CONSTRUCTED) |
295 | | it->utype); | 295 | | it->utype); |
296 | } | 296 | } |
297 | 297 | ||
298 | ptmpval = cf->asn1_d2i(pval, in, len); | 298 | ptmpval = cf->asn1_d2i(pval, in, len); |
299 | 299 | ||
@@ -313,15 +313,15 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, | |||
313 | 313 | ||
314 | /* Allocate structure */ | 314 | /* Allocate structure */ |
315 | if (!*pval && !ASN1_item_ex_new(pval, it)) | 315 | if (!*pval && !ASN1_item_ex_new(pval, it)) |
316 | { | 316 | { |
317 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, | 317 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, |
318 | ERR_R_NESTED_ASN1_ERROR); | 318 | ERR_R_NESTED_ASN1_ERROR); |
319 | goto err; | 319 | goto err; |
320 | } | 320 | } |
321 | /* CHOICE type, try each possibility in turn */ | 321 | /* CHOICE type, try each possibility in turn */ |
322 | p = *in; | 322 | p = *in; |
323 | for (i = 0, tt=it->templates; i < it->tcount; i++, tt++) | 323 | for (i = 0, tt=it->templates; i < it->tcount; i++, tt++) |
324 | { | 324 | { |
325 | pchptr = asn1_get_field_ptr(pval, tt); | 325 | pchptr = asn1_get_field_ptr(pval, tt); |
326 | /* We mark field as OPTIONAL so its absence | 326 | /* We mark field as OPTIONAL so its absence |
327 | * can be recognised. | 327 | * can be recognised. |
@@ -338,22 +338,22 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, | |||
338 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, | 338 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, |
339 | ERR_R_NESTED_ASN1_ERROR); | 339 | ERR_R_NESTED_ASN1_ERROR); |
340 | goto err; | 340 | goto err; |
341 | } | 341 | } |
342 | 342 | ||
343 | /* Did we fall off the end without reading anything? */ | 343 | /* Did we fall off the end without reading anything? */ |
344 | if (i == it->tcount) | 344 | if (i == it->tcount) |
345 | { | 345 | { |
346 | /* If OPTIONAL, this is OK */ | 346 | /* If OPTIONAL, this is OK */ |
347 | if (opt) | 347 | if (opt) |
348 | { | 348 | { |
349 | /* Free and zero it */ | 349 | /* Free and zero it */ |
350 | ASN1_item_ex_free(pval, it); | 350 | ASN1_item_ex_free(pval, it); |
351 | return -1; | 351 | return -1; |
352 | } | 352 | } |
353 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, | 353 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, |
354 | ASN1_R_NO_MATCHING_CHOICE_TYPE); | 354 | ASN1_R_NO_MATCHING_CHOICE_TYPE); |
355 | goto err; | 355 | goto err; |
356 | } | 356 | } |
357 | 357 | ||
358 | asn1_set_choice_selector(pval, i, it); | 358 | asn1_set_choice_selector(pval, i, it); |
359 | *in = p; | 359 | *in = p; |
@@ -368,48 +368,48 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, | |||
368 | 368 | ||
369 | /* If no IMPLICIT tagging set to SEQUENCE, UNIVERSAL */ | 369 | /* If no IMPLICIT tagging set to SEQUENCE, UNIVERSAL */ |
370 | if (tag == -1) | 370 | if (tag == -1) |
371 | { | 371 | { |
372 | tag = V_ASN1_SEQUENCE; | 372 | tag = V_ASN1_SEQUENCE; |
373 | aclass = V_ASN1_UNIVERSAL; | 373 | aclass = V_ASN1_UNIVERSAL; |
374 | } | 374 | } |
375 | /* Get SEQUENCE length and update len, p */ | 375 | /* Get SEQUENCE length and update len, p */ |
376 | ret = asn1_check_tlen(&len, NULL, NULL, &seq_eoc, &cst, | 376 | ret = asn1_check_tlen(&len, NULL, NULL, &seq_eoc, &cst, |
377 | &p, len, tag, aclass, opt, ctx); | 377 | &p, len, tag, aclass, opt, ctx); |
378 | if (!ret) | 378 | if (!ret) |
379 | { | 379 | { |
380 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, | 380 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, |
381 | ERR_R_NESTED_ASN1_ERROR); | 381 | ERR_R_NESTED_ASN1_ERROR); |
382 | goto err; | 382 | goto err; |
383 | } | 383 | } |
384 | else if (ret == -1) | 384 | else if (ret == -1) |
385 | return -1; | 385 | return -1; |
386 | if (aux && (aux->flags & ASN1_AFLG_BROKEN)) | 386 | if (aux && (aux->flags & ASN1_AFLG_BROKEN)) |
387 | { | 387 | { |
388 | len = tmplen - (p - *in); | 388 | len = tmplen - (p - *in); |
389 | seq_nolen = 1; | 389 | seq_nolen = 1; |
390 | } | 390 | } |
391 | /* If indefinite we don't do a length check */ | 391 | /* If indefinite we don't do a length check */ |
392 | else seq_nolen = seq_eoc; | 392 | else seq_nolen = seq_eoc; |
393 | if (!cst) | 393 | if (!cst) |
394 | { | 394 | { |
395 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, | 395 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, |
396 | ASN1_R_SEQUENCE_NOT_CONSTRUCTED); | 396 | ASN1_R_SEQUENCE_NOT_CONSTRUCTED); |
397 | goto err; | 397 | goto err; |
398 | } | 398 | } |
399 | 399 | ||
400 | if (!*pval && !ASN1_item_ex_new(pval, it)) | 400 | if (!*pval && !ASN1_item_ex_new(pval, it)) |
401 | { | 401 | { |
402 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, | 402 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, |
403 | ERR_R_NESTED_ASN1_ERROR); | 403 | ERR_R_NESTED_ASN1_ERROR); |
404 | goto err; | 404 | goto err; |
405 | } | 405 | } |
406 | 406 | ||
407 | if (asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it, NULL)) | 407 | if (asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it, NULL)) |
408 | goto auxerr; | 408 | goto auxerr; |
409 | 409 | ||
410 | /* Get each field entry */ | 410 | /* Get each field entry */ |
411 | for (i = 0, tt = it->templates; i < it->tcount; i++, tt++) | 411 | for (i = 0, tt = it->templates; i < it->tcount; i++, tt++) |
412 | { | 412 | { |
413 | const ASN1_TEMPLATE *seqtt; | 413 | const ASN1_TEMPLATE *seqtt; |
414 | ASN1_VALUE **pseqval; | 414 | ASN1_VALUE **pseqval; |
415 | seqtt = asn1_do_adb(pval, tt, 1); | 415 | seqtt = asn1_do_adb(pval, tt, 1); |
@@ -421,18 +421,18 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, | |||
421 | break; | 421 | break; |
422 | q = p; | 422 | q = p; |
423 | if (asn1_check_eoc(&p, len)) | 423 | if (asn1_check_eoc(&p, len)) |
424 | { | 424 | { |
425 | if (!seq_eoc) | 425 | if (!seq_eoc) |
426 | { | 426 | { |
427 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, | 427 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, |
428 | ASN1_R_UNEXPECTED_EOC); | 428 | ASN1_R_UNEXPECTED_EOC); |
429 | goto err; | 429 | goto err; |
430 | } | 430 | } |
431 | len -= p - q; | 431 | len -= p - q; |
432 | seq_eoc = 0; | 432 | seq_eoc = 0; |
433 | q = p; | 433 | q = p; |
434 | break; | 434 | break; |
435 | } | 435 | } |
436 | /* This determines the OPTIONAL flag value. The field | 436 | /* This determines the OPTIONAL flag value. The field |
437 | * cannot be omitted if it is the last of a SEQUENCE | 437 | * cannot be omitted if it is the last of a SEQUENCE |
438 | * and there is still data to be read. This isn't | 438 | * and there is still data to be read. This isn't |
@@ -448,60 +448,60 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, | |||
448 | ret = asn1_template_ex_d2i(pseqval, &p, len, | 448 | ret = asn1_template_ex_d2i(pseqval, &p, len, |
449 | seqtt, isopt, ctx); | 449 | seqtt, isopt, ctx); |
450 | if (!ret) | 450 | if (!ret) |
451 | { | 451 | { |
452 | errtt = seqtt; | 452 | errtt = seqtt; |
453 | goto err; | 453 | goto err; |
454 | } | 454 | } |
455 | else if (ret == -1) | 455 | else if (ret == -1) |
456 | { | 456 | { |
457 | /* OPTIONAL component absent. | 457 | /* OPTIONAL component absent. |
458 | * Free and zero the field. | 458 | * Free and zero the field. |
459 | */ | 459 | */ |
460 | ASN1_template_free(pseqval, seqtt); | 460 | ASN1_template_free(pseqval, seqtt); |
461 | continue; | 461 | continue; |
462 | } | 462 | } |
463 | /* Update length */ | 463 | /* Update length */ |
464 | len -= p - q; | 464 | len -= p - q; |
465 | } | 465 | } |
466 | 466 | ||
467 | /* Check for EOC if expecting one */ | 467 | /* Check for EOC if expecting one */ |
468 | if (seq_eoc && !asn1_check_eoc(&p, len)) | 468 | if (seq_eoc && !asn1_check_eoc(&p, len)) |
469 | { | 469 | { |
470 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_MISSING_EOC); | 470 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_MISSING_EOC); |
471 | goto err; | 471 | goto err; |
472 | } | 472 | } |
473 | /* Check all data read */ | 473 | /* Check all data read */ |
474 | if (!seq_nolen && len) | 474 | if (!seq_nolen && len) |
475 | { | 475 | { |
476 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, | 476 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, |
477 | ASN1_R_SEQUENCE_LENGTH_MISMATCH); | 477 | ASN1_R_SEQUENCE_LENGTH_MISMATCH); |
478 | goto err; | 478 | goto err; |
479 | } | 479 | } |
480 | 480 | ||
481 | /* If we get here we've got no more data in the SEQUENCE, | 481 | /* If we get here we've got no more data in the SEQUENCE, |
482 | * however we may not have read all fields so check all | 482 | * however we may not have read all fields so check all |
483 | * remaining are OPTIONAL and clear any that are. | 483 | * remaining are OPTIONAL and clear any that are. |
484 | */ | 484 | */ |
485 | for (; i < it->tcount; tt++, i++) | 485 | for (; i < it->tcount; tt++, i++) |
486 | { | 486 | { |
487 | const ASN1_TEMPLATE *seqtt; | 487 | const ASN1_TEMPLATE *seqtt; |
488 | seqtt = asn1_do_adb(pval, tt, 1); | 488 | seqtt = asn1_do_adb(pval, tt, 1); |
489 | if (!seqtt) | 489 | if (!seqtt) |
490 | goto err; | 490 | goto err; |
491 | if (seqtt->flags & ASN1_TFLG_OPTIONAL) | 491 | if (seqtt->flags & ASN1_TFLG_OPTIONAL) |
492 | { | 492 | { |
493 | ASN1_VALUE **pseqval; | 493 | ASN1_VALUE **pseqval; |
494 | pseqval = asn1_get_field_ptr(pval, seqtt); | 494 | pseqval = asn1_get_field_ptr(pval, seqtt); |
495 | ASN1_template_free(pseqval, seqtt); | 495 | ASN1_template_free(pseqval, seqtt); |
496 | } | 496 | } |
497 | else | 497 | else |
498 | { | 498 | { |
499 | errtt = seqtt; | 499 | errtt = seqtt; |
500 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, | 500 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, |
501 | ASN1_R_FIELD_MISSING); | 501 | ASN1_R_FIELD_MISSING); |
502 | goto err; | 502 | goto err; |
503 | } | ||
504 | } | 503 | } |
504 | } | ||
505 | /* Save encoding */ | 505 | /* Save encoding */ |
506 | if (!asn1_enc_save(pval, *in, p - *in, it)) | 506 | if (!asn1_enc_save(pval, *in, p - *in, it)) |
507 | goto auxerr; | 507 | goto auxerr; |
@@ -512,7 +512,7 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, | |||
512 | 512 | ||
513 | default: | 513 | default: |
514 | return 0; | 514 | return 0; |
515 | } | 515 | } |
516 | auxerr: | 516 | auxerr: |
517 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_AUX_ERROR); | 517 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_AUX_ERROR); |
518 | err: | 518 | err: |
@@ -523,7 +523,7 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, | |||
523 | else | 523 | else |
524 | ERR_add_error_data(2, "Type=", it->sname); | 524 | ERR_add_error_data(2, "Type=", it->sname); |
525 | return 0; | 525 | return 0; |
526 | } | 526 | } |
527 | 527 | ||
528 | /* Templates are handled with two separate functions. | 528 | /* Templates are handled with two separate functions. |
529 | * One handles any EXPLICIT tag and the other handles the rest. | 529 | * One handles any EXPLICIT tag and the other handles the rest. |
@@ -533,7 +533,7 @@ static int asn1_template_ex_d2i(ASN1_VALUE **val, | |||
533 | const unsigned char **in, long inlen, | 533 | const unsigned char **in, long inlen, |
534 | const ASN1_TEMPLATE *tt, char opt, | 534 | const ASN1_TEMPLATE *tt, char opt, |
535 | ASN1_TLC *ctx) | 535 | ASN1_TLC *ctx) |
536 | { | 536 | { |
537 | int flags, aclass; | 537 | int flags, aclass; |
538 | int ret; | 538 | int ret; |
539 | long len; | 539 | long len; |
@@ -548,7 +548,7 @@ static int asn1_template_ex_d2i(ASN1_VALUE **val, | |||
548 | 548 | ||
549 | /* Check if EXPLICIT tag expected */ | 549 | /* Check if EXPLICIT tag expected */ |
550 | if (flags & ASN1_TFLG_EXPTAG) | 550 | if (flags & ASN1_TFLG_EXPTAG) |
551 | { | 551 | { |
552 | char cst; | 552 | char cst; |
553 | /* Need to work out amount of data available to the inner | 553 | /* Need to work out amount of data available to the inner |
554 | * content and where it starts: so read in EXPLICIT header to | 554 | * content and where it starts: so read in EXPLICIT header to |
@@ -558,51 +558,51 @@ static int asn1_template_ex_d2i(ASN1_VALUE **val, | |||
558 | &p, inlen, tt->tag, aclass, opt, ctx); | 558 | &p, inlen, tt->tag, aclass, opt, ctx); |
559 | q = p; | 559 | q = p; |
560 | if (!ret) | 560 | if (!ret) |
561 | { | 561 | { |
562 | ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, | 562 | ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, |
563 | ERR_R_NESTED_ASN1_ERROR); | 563 | ERR_R_NESTED_ASN1_ERROR); |
564 | return 0; | 564 | return 0; |
565 | } | 565 | } |
566 | else if (ret == -1) | 566 | else if (ret == -1) |
567 | return -1; | 567 | return -1; |
568 | if (!cst) | 568 | if (!cst) |
569 | { | 569 | { |
570 | ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, | 570 | ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, |
571 | ASN1_R_EXPLICIT_TAG_NOT_CONSTRUCTED); | 571 | ASN1_R_EXPLICIT_TAG_NOT_CONSTRUCTED); |
572 | return 0; | 572 | return 0; |
573 | } | 573 | } |
574 | /* We've found the field so it can't be OPTIONAL now */ | 574 | /* We've found the field so it can't be OPTIONAL now */ |
575 | ret = asn1_template_noexp_d2i(val, &p, len, tt, 0, ctx); | 575 | ret = asn1_template_noexp_d2i(val, &p, len, tt, 0, ctx); |
576 | if (!ret) | 576 | if (!ret) |
577 | { | 577 | { |
578 | ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, | 578 | ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, |
579 | ERR_R_NESTED_ASN1_ERROR); | 579 | ERR_R_NESTED_ASN1_ERROR); |
580 | return 0; | 580 | return 0; |
581 | } | 581 | } |
582 | /* We read the field in OK so update length */ | 582 | /* We read the field in OK so update length */ |
583 | len -= p - q; | 583 | len -= p - q; |
584 | if (exp_eoc) | 584 | if (exp_eoc) |
585 | { | 585 | { |
586 | /* If NDEF we must have an EOC here */ | 586 | /* If NDEF we must have an EOC here */ |
587 | if (!asn1_check_eoc(&p, len)) | 587 | if (!asn1_check_eoc(&p, len)) |
588 | { | 588 | { |
589 | ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, | 589 | ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, |
590 | ASN1_R_MISSING_EOC); | 590 | ASN1_R_MISSING_EOC); |
591 | goto err; | 591 | goto err; |
592 | } | ||
593 | } | 592 | } |
593 | } | ||
594 | else | 594 | else |
595 | { | 595 | { |
596 | /* Otherwise we must hit the EXPLICIT tag end or its | 596 | /* Otherwise we must hit the EXPLICIT tag end or its |
597 | * an error */ | 597 | * an error */ |
598 | if (len) | 598 | if (len) |
599 | { | 599 | { |
600 | ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, | 600 | ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, |
601 | ASN1_R_EXPLICIT_LENGTH_MISMATCH); | 601 | ASN1_R_EXPLICIT_LENGTH_MISMATCH); |
602 | goto err; | 602 | goto err; |
603 | } | ||
604 | } | 603 | } |
605 | } | 604 | } |
605 | } | ||
606 | else | 606 | else |
607 | return asn1_template_noexp_d2i(val, in, inlen, | 607 | return asn1_template_noexp_d2i(val, in, inlen, |
608 | tt, opt, ctx); | 608 | tt, opt, ctx); |
@@ -613,13 +613,13 @@ static int asn1_template_ex_d2i(ASN1_VALUE **val, | |||
613 | err: | 613 | err: |
614 | ASN1_template_free(val, tt); | 614 | ASN1_template_free(val, tt); |
615 | return 0; | 615 | return 0; |
616 | } | 616 | } |
617 | 617 | ||
618 | static int asn1_template_noexp_d2i(ASN1_VALUE **val, | 618 | static int asn1_template_noexp_d2i(ASN1_VALUE **val, |
619 | const unsigned char **in, long len, | 619 | const unsigned char **in, long len, |
620 | const ASN1_TEMPLATE *tt, char opt, | 620 | const ASN1_TEMPLATE *tt, char opt, |
621 | ASN1_TLC *ctx) | 621 | ASN1_TLC *ctx) |
622 | { | 622 | { |
623 | int flags, aclass; | 623 | int flags, aclass; |
624 | int ret; | 624 | int ret; |
625 | const unsigned char *p, *q; | 625 | const unsigned char *p, *q; |
@@ -632,128 +632,128 @@ static int asn1_template_noexp_d2i(ASN1_VALUE **val, | |||
632 | q = p; | 632 | q = p; |
633 | 633 | ||
634 | if (flags & ASN1_TFLG_SK_MASK) | 634 | if (flags & ASN1_TFLG_SK_MASK) |
635 | { | 635 | { |
636 | /* SET OF, SEQUENCE OF */ | 636 | /* SET OF, SEQUENCE OF */ |
637 | int sktag, skaclass; | 637 | int sktag, skaclass; |
638 | char sk_eoc; | 638 | char sk_eoc; |
639 | /* First work out expected inner tag value */ | 639 | /* First work out expected inner tag value */ |
640 | if (flags & ASN1_TFLG_IMPTAG) | 640 | if (flags & ASN1_TFLG_IMPTAG) |
641 | { | 641 | { |
642 | sktag = tt->tag; | 642 | sktag = tt->tag; |
643 | skaclass = aclass; | 643 | skaclass = aclass; |
644 | } | 644 | } |
645 | else | 645 | else |
646 | { | 646 | { |
647 | skaclass = V_ASN1_UNIVERSAL; | 647 | skaclass = V_ASN1_UNIVERSAL; |
648 | if (flags & ASN1_TFLG_SET_OF) | 648 | if (flags & ASN1_TFLG_SET_OF) |
649 | sktag = V_ASN1_SET; | 649 | sktag = V_ASN1_SET; |
650 | else | 650 | else |
651 | sktag = V_ASN1_SEQUENCE; | 651 | sktag = V_ASN1_SEQUENCE; |
652 | } | 652 | } |
653 | /* Get the tag */ | 653 | /* Get the tag */ |
654 | ret = asn1_check_tlen(&len, NULL, NULL, &sk_eoc, NULL, | 654 | ret = asn1_check_tlen(&len, NULL, NULL, &sk_eoc, NULL, |
655 | &p, len, sktag, skaclass, opt, ctx); | 655 | &p, len, sktag, skaclass, opt, ctx); |
656 | if (!ret) | 656 | if (!ret) |
657 | { | 657 | { |
658 | ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, | 658 | ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, |
659 | ERR_R_NESTED_ASN1_ERROR); | 659 | ERR_R_NESTED_ASN1_ERROR); |
660 | return 0; | 660 | return 0; |
661 | } | 661 | } |
662 | else if (ret == -1) | 662 | else if (ret == -1) |
663 | return -1; | 663 | return -1; |
664 | if (!*val) | 664 | if (!*val) |
665 | *val = (ASN1_VALUE *)sk_new_null(); | 665 | *val = (ASN1_VALUE *)sk_new_null(); |
666 | else | 666 | else |
667 | { | 667 | { |
668 | /* We've got a valid STACK: free up any items present */ | 668 | /* We've got a valid STACK: free up any items present */ |
669 | STACK_OF(ASN1_VALUE) *sktmp | 669 | STACK_OF(ASN1_VALUE) *sktmp |
670 | = (STACK_OF(ASN1_VALUE) *)*val; | 670 | = (STACK_OF(ASN1_VALUE) *)*val; |
671 | ASN1_VALUE *vtmp; | 671 | ASN1_VALUE *vtmp; |
672 | while(sk_ASN1_VALUE_num(sktmp) > 0) | 672 | while(sk_ASN1_VALUE_num(sktmp) > 0) |
673 | { | 673 | { |
674 | vtmp = sk_ASN1_VALUE_pop(sktmp); | 674 | vtmp = sk_ASN1_VALUE_pop(sktmp); |
675 | ASN1_item_ex_free(&vtmp, | 675 | ASN1_item_ex_free(&vtmp, |
676 | ASN1_ITEM_ptr(tt->item)); | 676 | ASN1_ITEM_ptr(tt->item)); |
677 | } | ||
678 | } | 677 | } |
678 | } | ||
679 | 679 | ||
680 | if (!*val) | 680 | if (!*val) |
681 | { | 681 | { |
682 | ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, | 682 | ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, |
683 | ERR_R_MALLOC_FAILURE); | 683 | ERR_R_MALLOC_FAILURE); |
684 | goto err; | 684 | goto err; |
685 | } | 685 | } |
686 | 686 | ||
687 | /* Read as many items as we can */ | 687 | /* Read as many items as we can */ |
688 | while(len > 0) | 688 | while(len > 0) |
689 | { | 689 | { |
690 | ASN1_VALUE *skfield; | 690 | ASN1_VALUE *skfield; |
691 | q = p; | 691 | q = p; |
692 | /* See if EOC found */ | 692 | /* See if EOC found */ |
693 | if (asn1_check_eoc(&p, len)) | 693 | if (asn1_check_eoc(&p, len)) |
694 | { | 694 | { |
695 | if (!sk_eoc) | 695 | if (!sk_eoc) |
696 | { | 696 | { |
697 | ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, | 697 | ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, |
698 | ASN1_R_UNEXPECTED_EOC); | 698 | ASN1_R_UNEXPECTED_EOC); |
699 | goto err; | 699 | goto err; |
700 | } | 700 | } |
701 | len -= p - q; | 701 | len -= p - q; |
702 | sk_eoc = 0; | 702 | sk_eoc = 0; |
703 | break; | 703 | break; |
704 | } | 704 | } |
705 | skfield = NULL; | 705 | skfield = NULL; |
706 | if (!ASN1_item_ex_d2i(&skfield, &p, len, | 706 | if (!ASN1_item_ex_d2i(&skfield, &p, len, |
707 | ASN1_ITEM_ptr(tt->item), | 707 | ASN1_ITEM_ptr(tt->item), |
708 | -1, 0, 0, ctx)) | 708 | -1, 0, 0, ctx)) |
709 | { | 709 | { |
710 | ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, | 710 | ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, |
711 | ERR_R_NESTED_ASN1_ERROR); | 711 | ERR_R_NESTED_ASN1_ERROR); |
712 | goto err; | 712 | goto err; |
713 | } | 713 | } |
714 | len -= p - q; | 714 | len -= p - q; |
715 | if (!sk_ASN1_VALUE_push((STACK_OF(ASN1_VALUE) *)*val, | 715 | if (!sk_ASN1_VALUE_push((STACK_OF(ASN1_VALUE) *)*val, |
716 | skfield)) | 716 | skfield)) |
717 | { | 717 | { |
718 | ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, | 718 | ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, |
719 | ERR_R_MALLOC_FAILURE); | 719 | ERR_R_MALLOC_FAILURE); |
720 | goto err; | 720 | goto err; |
721 | } | ||
722 | } | 721 | } |
722 | } | ||
723 | if (sk_eoc) | 723 | if (sk_eoc) |
724 | { | 724 | { |
725 | ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, ASN1_R_MISSING_EOC); | 725 | ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, ASN1_R_MISSING_EOC); |
726 | goto err; | 726 | goto err; |
727 | } | ||
728 | } | 727 | } |
728 | } | ||
729 | else if (flags & ASN1_TFLG_IMPTAG) | 729 | else if (flags & ASN1_TFLG_IMPTAG) |
730 | { | 730 | { |
731 | /* IMPLICIT tagging */ | 731 | /* IMPLICIT tagging */ |
732 | ret = ASN1_item_ex_d2i(val, &p, len, | 732 | ret = ASN1_item_ex_d2i(val, &p, len, |
733 | ASN1_ITEM_ptr(tt->item), tt->tag, aclass, opt, ctx); | 733 | ASN1_ITEM_ptr(tt->item), tt->tag, aclass, opt, ctx); |
734 | if (!ret) | 734 | if (!ret) |
735 | { | 735 | { |
736 | ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, | 736 | ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, |
737 | ERR_R_NESTED_ASN1_ERROR); | 737 | ERR_R_NESTED_ASN1_ERROR); |
738 | goto err; | 738 | goto err; |
739 | } | 739 | } |
740 | else if (ret == -1) | 740 | else if (ret == -1) |
741 | return -1; | 741 | return -1; |
742 | } | 742 | } |
743 | else | 743 | else |
744 | { | 744 | { |
745 | /* Nothing special */ | 745 | /* Nothing special */ |
746 | ret = ASN1_item_ex_d2i(val, &p, len, ASN1_ITEM_ptr(tt->item), | 746 | ret = ASN1_item_ex_d2i(val, &p, len, ASN1_ITEM_ptr(tt->item), |
747 | -1, 0, opt, ctx); | 747 | -1, 0, opt, ctx); |
748 | if (!ret) | 748 | if (!ret) |
749 | { | 749 | { |
750 | ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, | 750 | ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, |
751 | ERR_R_NESTED_ASN1_ERROR); | 751 | ERR_R_NESTED_ASN1_ERROR); |
752 | goto err; | 752 | goto err; |
753 | } | 753 | } |
754 | else if (ret == -1) | 754 | else if (ret == -1) |
755 | return -1; | 755 | return -1; |
756 | } | 756 | } |
757 | 757 | ||
758 | *in = p; | 758 | *in = p; |
759 | return 1; | 759 | return 1; |
@@ -761,13 +761,13 @@ static int asn1_template_noexp_d2i(ASN1_VALUE **val, | |||
761 | err: | 761 | err: |
762 | ASN1_template_free(val, tt); | 762 | ASN1_template_free(val, tt); |
763 | return 0; | 763 | return 0; |
764 | } | 764 | } |
765 | 765 | ||
766 | static int asn1_d2i_ex_primitive(ASN1_VALUE **pval, | 766 | static int asn1_d2i_ex_primitive(ASN1_VALUE **pval, |
767 | const unsigned char **in, long inlen, | 767 | const unsigned char **in, long inlen, |
768 | const ASN1_ITEM *it, | 768 | const ASN1_ITEM *it, |
769 | int tag, int aclass, char opt, ASN1_TLC *ctx) | 769 | int tag, int aclass, char opt, ASN1_TLC *ctx) |
770 | { | 770 | { |
771 | int ret = 0, utype; | 771 | int ret = 0, utype; |
772 | long plen; | 772 | long plen; |
773 | char cst, inf, free_cont = 0; | 773 | char cst, inf, free_cont = 0; |
@@ -776,100 +776,100 @@ static int asn1_d2i_ex_primitive(ASN1_VALUE **pval, | |||
776 | const unsigned char *cont = NULL; | 776 | const unsigned char *cont = NULL; |
777 | long len; | 777 | long len; |
778 | if (!pval) | 778 | if (!pval) |
779 | { | 779 | { |
780 | ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ASN1_R_ILLEGAL_NULL); | 780 | ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ASN1_R_ILLEGAL_NULL); |
781 | return 0; /* Should never happen */ | 781 | return 0; /* Should never happen */ |
782 | } | 782 | } |
783 | 783 | ||
784 | if (it->itype == ASN1_ITYPE_MSTRING) | 784 | if (it->itype == ASN1_ITYPE_MSTRING) |
785 | { | 785 | { |
786 | utype = tag; | 786 | utype = tag; |
787 | tag = -1; | 787 | tag = -1; |
788 | } | 788 | } |
789 | else | 789 | else |
790 | utype = it->utype; | 790 | utype = it->utype; |
791 | 791 | ||
792 | if (utype == V_ASN1_ANY) | 792 | if (utype == V_ASN1_ANY) |
793 | { | 793 | { |
794 | /* If type is ANY need to figure out type from tag */ | 794 | /* If type is ANY need to figure out type from tag */ |
795 | unsigned char oclass; | 795 | unsigned char oclass; |
796 | if (tag >= 0) | 796 | if (tag >= 0) |
797 | { | 797 | { |
798 | ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, | 798 | ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, |
799 | ASN1_R_ILLEGAL_TAGGED_ANY); | 799 | ASN1_R_ILLEGAL_TAGGED_ANY); |
800 | return 0; | 800 | return 0; |
801 | } | 801 | } |
802 | if (opt) | 802 | if (opt) |
803 | { | 803 | { |
804 | ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, | 804 | ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, |
805 | ASN1_R_ILLEGAL_OPTIONAL_ANY); | 805 | ASN1_R_ILLEGAL_OPTIONAL_ANY); |
806 | return 0; | 806 | return 0; |
807 | } | 807 | } |
808 | p = *in; | 808 | p = *in; |
809 | ret = asn1_check_tlen(NULL, &utype, &oclass, NULL, NULL, | 809 | ret = asn1_check_tlen(NULL, &utype, &oclass, NULL, NULL, |
810 | &p, inlen, -1, 0, 0, ctx); | 810 | &p, inlen, -1, 0, 0, ctx); |
811 | if (!ret) | 811 | if (!ret) |
812 | { | 812 | { |
813 | ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, | 813 | ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, |
814 | ERR_R_NESTED_ASN1_ERROR); | 814 | ERR_R_NESTED_ASN1_ERROR); |
815 | return 0; | 815 | return 0; |
816 | } | 816 | } |
817 | if (oclass != V_ASN1_UNIVERSAL) | 817 | if (oclass != V_ASN1_UNIVERSAL) |
818 | utype = V_ASN1_OTHER; | 818 | utype = V_ASN1_OTHER; |
819 | } | 819 | } |
820 | if (tag == -1) | 820 | if (tag == -1) |
821 | { | 821 | { |
822 | tag = utype; | 822 | tag = utype; |
823 | aclass = V_ASN1_UNIVERSAL; | 823 | aclass = V_ASN1_UNIVERSAL; |
824 | } | 824 | } |
825 | p = *in; | 825 | p = *in; |
826 | /* Check header */ | 826 | /* Check header */ |
827 | ret = asn1_check_tlen(&plen, NULL, NULL, &inf, &cst, | 827 | ret = asn1_check_tlen(&plen, NULL, NULL, &inf, &cst, |
828 | &p, inlen, tag, aclass, opt, ctx); | 828 | &p, inlen, tag, aclass, opt, ctx); |
829 | if (!ret) | 829 | if (!ret) |
830 | { | 830 | { |
831 | ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ERR_R_NESTED_ASN1_ERROR); | 831 | ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ERR_R_NESTED_ASN1_ERROR); |
832 | return 0; | 832 | return 0; |
833 | } | 833 | } |
834 | else if (ret == -1) | 834 | else if (ret == -1) |
835 | return -1; | 835 | return -1; |
836 | ret = 0; | 836 | ret = 0; |
837 | /* SEQUENCE, SET and "OTHER" are left in encoded form */ | 837 | /* SEQUENCE, SET and "OTHER" are left in encoded form */ |
838 | if ((utype == V_ASN1_SEQUENCE) | 838 | if ((utype == V_ASN1_SEQUENCE) |
839 | || (utype == V_ASN1_SET) || (utype == V_ASN1_OTHER)) | 839 | || (utype == V_ASN1_SET) || (utype == V_ASN1_OTHER)) |
840 | { | 840 | { |
841 | /* Clear context cache for type OTHER because the auto clear | 841 | /* Clear context cache for type OTHER because the auto clear |
842 | * when we have a exact match wont work | 842 | * when we have a exact match wont work |
843 | */ | 843 | */ |
844 | if (utype == V_ASN1_OTHER) | 844 | if (utype == V_ASN1_OTHER) |
845 | { | 845 | { |
846 | asn1_tlc_clear(ctx); | 846 | asn1_tlc_clear(ctx); |
847 | } | 847 | } |
848 | /* SEQUENCE and SET must be constructed */ | 848 | /* SEQUENCE and SET must be constructed */ |
849 | else if (!cst) | 849 | else if (!cst) |
850 | { | 850 | { |
851 | ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, | 851 | ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, |
852 | ASN1_R_TYPE_NOT_CONSTRUCTED); | 852 | ASN1_R_TYPE_NOT_CONSTRUCTED); |
853 | return 0; | 853 | return 0; |
854 | } | 854 | } |
855 | 855 | ||
856 | cont = *in; | 856 | cont = *in; |
857 | /* If indefinite length constructed find the real end */ | 857 | /* If indefinite length constructed find the real end */ |
858 | if (inf) | 858 | if (inf) |
859 | { | 859 | { |
860 | if (!asn1_find_end(&p, plen, inf)) | 860 | if (!asn1_find_end(&p, plen, inf)) |
861 | goto err; | 861 | goto err; |
862 | len = p - cont; | 862 | len = p - cont; |
863 | } | 863 | } |
864 | else | 864 | else |
865 | { | 865 | { |
866 | len = p - cont + plen; | 866 | len = p - cont + plen; |
867 | p += plen; | 867 | p += plen; |
868 | buf.data = NULL; | 868 | buf.data = NULL; |
869 | } | ||
870 | } | 869 | } |
870 | } | ||
871 | else if (cst) | 871 | else if (cst) |
872 | { | 872 | { |
873 | buf.length = 0; | 873 | buf.length = 0; |
874 | buf.max = 0; | 874 | buf.max = 0; |
875 | buf.data = NULL; | 875 | buf.data = NULL; |
@@ -880,28 +880,28 @@ static int asn1_d2i_ex_primitive(ASN1_VALUE **pval, | |||
880 | * for UNIVERSAL class and ignore the tag. | 880 | * for UNIVERSAL class and ignore the tag. |
881 | */ | 881 | */ |
882 | if (!asn1_collect(&buf, &p, plen, inf, -1, V_ASN1_UNIVERSAL, 0)) | 882 | if (!asn1_collect(&buf, &p, plen, inf, -1, V_ASN1_UNIVERSAL, 0)) |
883 | { | 883 | { |
884 | free_cont = 1; | 884 | free_cont = 1; |
885 | goto err; | 885 | goto err; |
886 | } | 886 | } |
887 | len = buf.length; | 887 | len = buf.length; |
888 | /* Append a final null to string */ | 888 | /* Append a final null to string */ |
889 | if (!BUF_MEM_grow_clean(&buf, len + 1)) | 889 | if (!BUF_MEM_grow_clean(&buf, len + 1)) |
890 | { | 890 | { |
891 | ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, | 891 | ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, |
892 | ERR_R_MALLOC_FAILURE); | 892 | ERR_R_MALLOC_FAILURE); |
893 | return 0; | 893 | return 0; |
894 | } | 894 | } |
895 | buf.data[len] = 0; | 895 | buf.data[len] = 0; |
896 | cont = (const unsigned char *)buf.data; | 896 | cont = (const unsigned char *)buf.data; |
897 | free_cont = 1; | 897 | free_cont = 1; |
898 | } | 898 | } |
899 | else | 899 | else |
900 | { | 900 | { |
901 | cont = p; | 901 | cont = p; |
902 | len = plen; | 902 | len = plen; |
903 | p += plen; | 903 | p += plen; |
904 | } | 904 | } |
905 | 905 | ||
906 | /* We now have content length and type: translate into a structure */ | 906 | /* We now have content length and type: translate into a structure */ |
907 | if (!asn1_ex_c2i(pval, cont, len, utype, &free_cont, it)) | 907 | if (!asn1_ex_c2i(pval, cont, len, utype, &free_cont, it)) |
@@ -912,13 +912,13 @@ static int asn1_d2i_ex_primitive(ASN1_VALUE **pval, | |||
912 | err: | 912 | err: |
913 | if (free_cont && buf.data) free(buf.data); | 913 | if (free_cont && buf.data) free(buf.data); |
914 | return ret; | 914 | return ret; |
915 | } | 915 | } |
916 | 916 | ||
917 | /* Translate ASN1 content octets into a structure */ | 917 | /* Translate ASN1 content octets into a structure */ |
918 | 918 | ||
919 | int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, | 919 | int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, |
920 | int utype, char *free_cont, const ASN1_ITEM *it) | 920 | int utype, char *free_cont, const ASN1_ITEM *it) |
921 | { | 921 | { |
922 | ASN1_VALUE **opval = NULL; | 922 | ASN1_VALUE **opval = NULL; |
923 | ASN1_STRING *stmp; | 923 | ASN1_STRING *stmp; |
924 | ASN1_TYPE *typ = NULL; | 924 | ASN1_TYPE *typ = NULL; |
@@ -931,14 +931,14 @@ int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, | |||
931 | return pf->prim_c2i(pval, cont, len, utype, free_cont, it); | 931 | return pf->prim_c2i(pval, cont, len, utype, free_cont, it); |
932 | /* If ANY type clear type and set pointer to internal value */ | 932 | /* If ANY type clear type and set pointer to internal value */ |
933 | if (it->utype == V_ASN1_ANY) | 933 | if (it->utype == V_ASN1_ANY) |
934 | { | 934 | { |
935 | if (!*pval) | 935 | if (!*pval) |
936 | { | 936 | { |
937 | typ = ASN1_TYPE_new(); | 937 | typ = ASN1_TYPE_new(); |
938 | if (typ == NULL) | 938 | if (typ == NULL) |
939 | goto err; | 939 | goto err; |
940 | *pval = (ASN1_VALUE *)typ; | 940 | *pval = (ASN1_VALUE *)typ; |
941 | } | 941 | } |
942 | else | 942 | else |
943 | typ = (ASN1_TYPE *)*pval; | 943 | typ = (ASN1_TYPE *)*pval; |
944 | 944 | ||
@@ -946,9 +946,9 @@ int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, | |||
946 | ASN1_TYPE_set(typ, utype, NULL); | 946 | ASN1_TYPE_set(typ, utype, NULL); |
947 | opval = pval; | 947 | opval = pval; |
948 | pval = &typ->value.asn1_value; | 948 | pval = &typ->value.asn1_value; |
949 | } | 949 | } |
950 | switch(utype) | 950 | switch(utype) |
951 | { | 951 | { |
952 | case V_ASN1_OBJECT: | 952 | case V_ASN1_OBJECT: |
953 | if (!c2i_ASN1_OBJECT((ASN1_OBJECT **)pval, &cont, len)) | 953 | if (!c2i_ASN1_OBJECT((ASN1_OBJECT **)pval, &cont, len)) |
954 | goto err; | 954 | goto err; |
@@ -956,27 +956,27 @@ int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, | |||
956 | 956 | ||
957 | case V_ASN1_NULL: | 957 | case V_ASN1_NULL: |
958 | if (len) | 958 | if (len) |
959 | { | 959 | { |
960 | ASN1err(ASN1_F_ASN1_EX_C2I, | 960 | ASN1err(ASN1_F_ASN1_EX_C2I, |
961 | ASN1_R_NULL_IS_WRONG_LENGTH); | 961 | ASN1_R_NULL_IS_WRONG_LENGTH); |
962 | goto err; | 962 | goto err; |
963 | } | 963 | } |
964 | *pval = (ASN1_VALUE *)1; | 964 | *pval = (ASN1_VALUE *)1; |
965 | break; | 965 | break; |
966 | 966 | ||
967 | case V_ASN1_BOOLEAN: | 967 | case V_ASN1_BOOLEAN: |
968 | if (len != 1) | 968 | if (len != 1) |
969 | { | 969 | { |
970 | ASN1err(ASN1_F_ASN1_EX_C2I, | 970 | ASN1err(ASN1_F_ASN1_EX_C2I, |
971 | ASN1_R_BOOLEAN_IS_WRONG_LENGTH); | 971 | ASN1_R_BOOLEAN_IS_WRONG_LENGTH); |
972 | goto err; | 972 | goto err; |
973 | } | 973 | } |
974 | else | 974 | else |
975 | { | 975 | { |
976 | ASN1_BOOLEAN *tbool; | 976 | ASN1_BOOLEAN *tbool; |
977 | tbool = (ASN1_BOOLEAN *)pval; | 977 | tbool = (ASN1_BOOLEAN *)pval; |
978 | *tbool = *cont; | 978 | *tbool = *cont; |
979 | } | 979 | } |
980 | break; | 980 | break; |
981 | 981 | ||
982 | case V_ASN1_BIT_STRING: | 982 | case V_ASN1_BIT_STRING: |
@@ -1014,56 +1014,56 @@ int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, | |||
1014 | case V_ASN1_SEQUENCE: | 1014 | case V_ASN1_SEQUENCE: |
1015 | default: | 1015 | default: |
1016 | if (utype == V_ASN1_BMPSTRING && (len & 1)) | 1016 | if (utype == V_ASN1_BMPSTRING && (len & 1)) |
1017 | { | 1017 | { |
1018 | ASN1err(ASN1_F_ASN1_EX_C2I, | 1018 | ASN1err(ASN1_F_ASN1_EX_C2I, |
1019 | ASN1_R_BMPSTRING_IS_WRONG_LENGTH); | 1019 | ASN1_R_BMPSTRING_IS_WRONG_LENGTH); |
1020 | goto err; | 1020 | goto err; |
1021 | } | 1021 | } |
1022 | if (utype == V_ASN1_UNIVERSALSTRING && (len & 3)) | 1022 | if (utype == V_ASN1_UNIVERSALSTRING && (len & 3)) |
1023 | { | 1023 | { |
1024 | ASN1err(ASN1_F_ASN1_EX_C2I, | 1024 | ASN1err(ASN1_F_ASN1_EX_C2I, |
1025 | ASN1_R_UNIVERSALSTRING_IS_WRONG_LENGTH); | 1025 | ASN1_R_UNIVERSALSTRING_IS_WRONG_LENGTH); |
1026 | goto err; | 1026 | goto err; |
1027 | } | 1027 | } |
1028 | /* All based on ASN1_STRING and handled the same */ | 1028 | /* All based on ASN1_STRING and handled the same */ |
1029 | if (!*pval) | 1029 | if (!*pval) |
1030 | { | 1030 | { |
1031 | stmp = ASN1_STRING_type_new(utype); | 1031 | stmp = ASN1_STRING_type_new(utype); |
1032 | if (!stmp) | 1032 | if (!stmp) |
1033 | { | 1033 | { |
1034 | ASN1err(ASN1_F_ASN1_EX_C2I, | 1034 | ASN1err(ASN1_F_ASN1_EX_C2I, |
1035 | ERR_R_MALLOC_FAILURE); | 1035 | ERR_R_MALLOC_FAILURE); |
1036 | goto err; | 1036 | goto err; |
1037 | } | ||
1038 | *pval = (ASN1_VALUE *)stmp; | ||
1039 | } | 1037 | } |
1038 | *pval = (ASN1_VALUE *)stmp; | ||
1039 | } | ||
1040 | else | 1040 | else |
1041 | { | 1041 | { |
1042 | stmp = (ASN1_STRING *)*pval; | 1042 | stmp = (ASN1_STRING *)*pval; |
1043 | stmp->type = utype; | 1043 | stmp->type = utype; |
1044 | } | 1044 | } |
1045 | /* If we've already allocated a buffer use it */ | 1045 | /* If we've already allocated a buffer use it */ |
1046 | if (*free_cont) | 1046 | if (*free_cont) |
1047 | { | 1047 | { |
1048 | if (stmp->data) | 1048 | if (stmp->data) |
1049 | free(stmp->data); | 1049 | free(stmp->data); |
1050 | stmp->data = (unsigned char *)cont; /* UGLY CAST! RL */ | 1050 | stmp->data = (unsigned char *)cont; /* UGLY CAST! RL */ |
1051 | stmp->length = len; | 1051 | stmp->length = len; |
1052 | *free_cont = 0; | 1052 | *free_cont = 0; |
1053 | } | 1053 | } |
1054 | else | 1054 | else |
1055 | { | 1055 | { |
1056 | if (!ASN1_STRING_set(stmp, cont, len)) | 1056 | if (!ASN1_STRING_set(stmp, cont, len)) |
1057 | { | 1057 | { |
1058 | ASN1err(ASN1_F_ASN1_EX_C2I, | 1058 | ASN1err(ASN1_F_ASN1_EX_C2I, |
1059 | ERR_R_MALLOC_FAILURE); | 1059 | ERR_R_MALLOC_FAILURE); |
1060 | ASN1_STRING_free(stmp); | 1060 | ASN1_STRING_free(stmp); |
1061 | *pval = NULL; | 1061 | *pval = NULL; |
1062 | goto err; | 1062 | goto err; |
1063 | } | ||
1064 | } | 1063 | } |
1065 | break; | ||
1066 | } | 1064 | } |
1065 | break; | ||
1066 | } | ||
1067 | /* If ASN1_ANY and NULL type fix up value */ | 1067 | /* If ASN1_ANY and NULL type fix up value */ |
1068 | if (typ && (utype == V_ASN1_NULL)) | 1068 | if (typ && (utype == V_ASN1_NULL)) |
1069 | typ->value.ptr = NULL; | 1069 | typ->value.ptr = NULL; |
@@ -1071,13 +1071,13 @@ int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, | |||
1071 | ret = 1; | 1071 | ret = 1; |
1072 | err: | 1072 | err: |
1073 | if (!ret) | 1073 | if (!ret) |
1074 | { | 1074 | { |
1075 | ASN1_TYPE_free(typ); | 1075 | ASN1_TYPE_free(typ); |
1076 | if (opval) | 1076 | if (opval) |
1077 | *opval = NULL; | 1077 | *opval = NULL; |
1078 | } | ||
1079 | return ret; | ||
1080 | } | 1078 | } |
1079 | return ret; | ||
1080 | } | ||
1081 | 1081 | ||
1082 | 1082 | ||
1083 | /* This function finds the end of an ASN1 structure when passed its maximum | 1083 | /* This function finds the end of an ASN1 structure when passed its maximum |
@@ -1087,16 +1087,16 @@ int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, | |||
1087 | */ | 1087 | */ |
1088 | 1088 | ||
1089 | static int asn1_find_end(const unsigned char **in, long len, char inf) | 1089 | static int asn1_find_end(const unsigned char **in, long len, char inf) |
1090 | { | 1090 | { |
1091 | int expected_eoc; | 1091 | int expected_eoc; |
1092 | long plen; | 1092 | long plen; |
1093 | const unsigned char *p = *in, *q; | 1093 | const unsigned char *p = *in, *q; |
1094 | /* If not indefinite length constructed just add length */ | 1094 | /* If not indefinite length constructed just add length */ |
1095 | if (inf == 0) | 1095 | if (inf == 0) |
1096 | { | 1096 | { |
1097 | *in += len; | 1097 | *in += len; |
1098 | return 1; | 1098 | return 1; |
1099 | } | 1099 | } |
1100 | expected_eoc = 1; | 1100 | expected_eoc = 1; |
1101 | /* Indefinite length constructed form. Find the end when enough EOCs | 1101 | /* Indefinite length constructed form. Find the end when enough EOCs |
1102 | * are found. If more indefinite length constructed headers | 1102 | * are found. If more indefinite length constructed headers |
@@ -1104,37 +1104,37 @@ static int asn1_find_end(const unsigned char **in, long len, char inf) | |||
1104 | * skip to the end of the data. | 1104 | * skip to the end of the data. |
1105 | */ | 1105 | */ |
1106 | while (len > 0) | 1106 | while (len > 0) |
1107 | { | 1107 | { |
1108 | if(asn1_check_eoc(&p, len)) | 1108 | if(asn1_check_eoc(&p, len)) |
1109 | { | 1109 | { |
1110 | expected_eoc--; | 1110 | expected_eoc--; |
1111 | if (expected_eoc == 0) | 1111 | if (expected_eoc == 0) |
1112 | break; | 1112 | break; |
1113 | len -= 2; | 1113 | len -= 2; |
1114 | continue; | 1114 | continue; |
1115 | } | 1115 | } |
1116 | q = p; | 1116 | q = p; |
1117 | /* Just read in a header: only care about the length */ | 1117 | /* Just read in a header: only care about the length */ |
1118 | if(!asn1_check_tlen(&plen, NULL, NULL, &inf, NULL, &p, len, | 1118 | if(!asn1_check_tlen(&plen, NULL, NULL, &inf, NULL, &p, len, |
1119 | -1, 0, 0, NULL)) | 1119 | -1, 0, 0, NULL)) |
1120 | { | 1120 | { |
1121 | ASN1err(ASN1_F_ASN1_FIND_END, ERR_R_NESTED_ASN1_ERROR); | 1121 | ASN1err(ASN1_F_ASN1_FIND_END, ERR_R_NESTED_ASN1_ERROR); |
1122 | return 0; | 1122 | return 0; |
1123 | } | 1123 | } |
1124 | if (inf) | 1124 | if (inf) |
1125 | expected_eoc++; | 1125 | expected_eoc++; |
1126 | else | 1126 | else |
1127 | p += plen; | 1127 | p += plen; |
1128 | len -= p - q; | 1128 | len -= p - q; |
1129 | } | 1129 | } |
1130 | if (expected_eoc) | 1130 | if (expected_eoc) |
1131 | { | 1131 | { |
1132 | ASN1err(ASN1_F_ASN1_FIND_END, ASN1_R_MISSING_EOC); | 1132 | ASN1err(ASN1_F_ASN1_FIND_END, ASN1_R_MISSING_EOC); |
1133 | return 0; | 1133 | return 0; |
1134 | } | 1134 | } |
1135 | *in = p; | 1135 | *in = p; |
1136 | return 1; | 1136 | return 1; |
1137 | } | 1137 | } |
1138 | /* This function collects the asn1 data from a constructred string | 1138 | /* This function collects the asn1 data from a constructred string |
1139 | * type into a buffer. The values of 'in' and 'len' should refer | 1139 | * type into a buffer. The values of 'in' and 'len' should refer |
1140 | * to the contents of the constructed type and 'inf' should be set | 1140 | * to the contents of the constructed type and 'inf' should be set |
@@ -1153,7 +1153,7 @@ static int asn1_find_end(const unsigned char **in, long len, char inf) | |||
1153 | 1153 | ||
1154 | static int asn1_collect(BUF_MEM *buf, const unsigned char **in, long len, | 1154 | static int asn1_collect(BUF_MEM *buf, const unsigned char **in, long len, |
1155 | char inf, int tag, int aclass, int depth) | 1155 | char inf, int tag, int aclass, int depth) |
1156 | { | 1156 | { |
1157 | const unsigned char *p, *q; | 1157 | const unsigned char *p, *q; |
1158 | long plen; | 1158 | long plen; |
1159 | char cst, ininf; | 1159 | char cst, ininf; |
@@ -1162,92 +1162,92 @@ static int asn1_collect(BUF_MEM *buf, const unsigned char **in, long len, | |||
1162 | /* If no buffer and not indefinite length constructed just pass over | 1162 | /* If no buffer and not indefinite length constructed just pass over |
1163 | * the encoded data */ | 1163 | * the encoded data */ |
1164 | if (!buf && !inf) | 1164 | if (!buf && !inf) |
1165 | { | 1165 | { |
1166 | *in += len; | 1166 | *in += len; |
1167 | return 1; | 1167 | return 1; |
1168 | } | 1168 | } |
1169 | while(len > 0) | 1169 | while(len > 0) |
1170 | { | 1170 | { |
1171 | q = p; | 1171 | q = p; |
1172 | /* Check for EOC */ | 1172 | /* Check for EOC */ |
1173 | if (asn1_check_eoc(&p, len)) | 1173 | if (asn1_check_eoc(&p, len)) |
1174 | { | 1174 | { |
1175 | /* EOC is illegal outside indefinite length | 1175 | /* EOC is illegal outside indefinite length |
1176 | * constructed form */ | 1176 | * constructed form */ |
1177 | if (!inf) | 1177 | if (!inf) |
1178 | { | 1178 | { |
1179 | ASN1err(ASN1_F_ASN1_COLLECT, | 1179 | ASN1err(ASN1_F_ASN1_COLLECT, |
1180 | ASN1_R_UNEXPECTED_EOC); | 1180 | ASN1_R_UNEXPECTED_EOC); |
1181 | return 0; | 1181 | return 0; |
1182 | } | 1182 | } |
1183 | inf = 0; | 1183 | inf = 0; |
1184 | break; | 1184 | break; |
1185 | } | 1185 | } |
1186 | 1186 | ||
1187 | if (!asn1_check_tlen(&plen, NULL, NULL, &ininf, &cst, &p, | 1187 | if (!asn1_check_tlen(&plen, NULL, NULL, &ininf, &cst, &p, |
1188 | len, tag, aclass, 0, NULL)) | 1188 | len, tag, aclass, 0, NULL)) |
1189 | { | 1189 | { |
1190 | ASN1err(ASN1_F_ASN1_COLLECT, ERR_R_NESTED_ASN1_ERROR); | 1190 | ASN1err(ASN1_F_ASN1_COLLECT, ERR_R_NESTED_ASN1_ERROR); |
1191 | return 0; | 1191 | return 0; |
1192 | } | 1192 | } |
1193 | 1193 | ||
1194 | /* If indefinite length constructed update max length */ | 1194 | /* If indefinite length constructed update max length */ |
1195 | if (cst) | 1195 | if (cst) |
1196 | { | 1196 | { |
1197 | if (depth >= ASN1_MAX_STRING_NEST) | 1197 | if (depth >= ASN1_MAX_STRING_NEST) |
1198 | { | 1198 | { |
1199 | ASN1err(ASN1_F_ASN1_COLLECT, | 1199 | ASN1err(ASN1_F_ASN1_COLLECT, |
1200 | ASN1_R_NESTED_ASN1_STRING); | 1200 | ASN1_R_NESTED_ASN1_STRING); |
1201 | return 0; | 1201 | return 0; |
1202 | } | 1202 | } |
1203 | if (!asn1_collect(buf, &p, plen, ininf, tag, aclass, | 1203 | if (!asn1_collect(buf, &p, plen, ininf, tag, aclass, |
1204 | depth + 1)) | 1204 | depth + 1)) |
1205 | return 0; | 1205 | return 0; |
1206 | } | 1206 | } |
1207 | else if (plen && !collect_data(buf, &p, plen)) | 1207 | else if (plen && !collect_data(buf, &p, plen)) |
1208 | return 0; | 1208 | return 0; |
1209 | len -= p - q; | 1209 | len -= p - q; |
1210 | } | 1210 | } |
1211 | if (inf) | 1211 | if (inf) |
1212 | { | 1212 | { |
1213 | ASN1err(ASN1_F_ASN1_COLLECT, ASN1_R_MISSING_EOC); | 1213 | ASN1err(ASN1_F_ASN1_COLLECT, ASN1_R_MISSING_EOC); |
1214 | return 0; | 1214 | return 0; |
1215 | } | 1215 | } |
1216 | *in = p; | 1216 | *in = p; |
1217 | return 1; | 1217 | return 1; |
1218 | } | 1218 | } |
1219 | 1219 | ||
1220 | static int collect_data(BUF_MEM *buf, const unsigned char **p, long plen) | 1220 | static int collect_data(BUF_MEM *buf, const unsigned char **p, long plen) |
1221 | { | 1221 | { |
1222 | int len; | 1222 | int len; |
1223 | if (buf) | 1223 | if (buf) |
1224 | { | 1224 | { |
1225 | len = buf->length; | 1225 | len = buf->length; |
1226 | if (!BUF_MEM_grow_clean(buf, len + plen)) | 1226 | if (!BUF_MEM_grow_clean(buf, len + plen)) |
1227 | { | 1227 | { |
1228 | ASN1err(ASN1_F_COLLECT_DATA, ERR_R_MALLOC_FAILURE); | 1228 | ASN1err(ASN1_F_COLLECT_DATA, ERR_R_MALLOC_FAILURE); |
1229 | return 0; | 1229 | return 0; |
1230 | } | ||
1231 | memcpy(buf->data + len, *p, plen); | ||
1232 | } | 1230 | } |
1231 | memcpy(buf->data + len, *p, plen); | ||
1232 | } | ||
1233 | *p += plen; | 1233 | *p += plen; |
1234 | return 1; | 1234 | return 1; |
1235 | } | 1235 | } |
1236 | 1236 | ||
1237 | /* Check for ASN1 EOC and swallow it if found */ | 1237 | /* Check for ASN1 EOC and swallow it if found */ |
1238 | 1238 | ||
1239 | static int asn1_check_eoc(const unsigned char **in, long len) | 1239 | static int asn1_check_eoc(const unsigned char **in, long len) |
1240 | { | 1240 | { |
1241 | const unsigned char *p; | 1241 | const unsigned char *p; |
1242 | if (len < 2) return 0; | 1242 | if (len < 2) return 0; |
1243 | p = *in; | 1243 | p = *in; |
1244 | if (!p[0] && !p[1]) | 1244 | if (!p[0] && !p[1]) |
1245 | { | 1245 | { |
1246 | *in += 2; | 1246 | *in += 2; |
1247 | return 1; | 1247 | return 1; |
1248 | } | ||
1249 | return 0; | ||
1250 | } | 1248 | } |
1249 | return 0; | ||
1250 | } | ||
1251 | 1251 | ||
1252 | /* Check an ASN1 tag and length: a bit like ASN1_get_object | 1252 | /* Check an ASN1 tag and length: a bit like ASN1_get_object |
1253 | * but it sets the length for indefinite length constructed | 1253 | * but it sets the length for indefinite length constructed |
@@ -1261,7 +1261,7 @@ static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass, | |||
1261 | const unsigned char **in, long len, | 1261 | const unsigned char **in, long len, |
1262 | int exptag, int expclass, char opt, | 1262 | int exptag, int expclass, char opt, |
1263 | ASN1_TLC *ctx) | 1263 | ASN1_TLC *ctx) |
1264 | { | 1264 | { |
1265 | int i; | 1265 | int i; |
1266 | int ptag, pclass; | 1266 | int ptag, pclass; |
1267 | long plen; | 1267 | long plen; |
@@ -1270,18 +1270,18 @@ static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass, | |||
1270 | q = p; | 1270 | q = p; |
1271 | 1271 | ||
1272 | if (ctx && ctx->valid) | 1272 | if (ctx && ctx->valid) |
1273 | { | 1273 | { |
1274 | i = ctx->ret; | 1274 | i = ctx->ret; |
1275 | plen = ctx->plen; | 1275 | plen = ctx->plen; |
1276 | pclass = ctx->pclass; | 1276 | pclass = ctx->pclass; |
1277 | ptag = ctx->ptag; | 1277 | ptag = ctx->ptag; |
1278 | p += ctx->hdrlen; | 1278 | p += ctx->hdrlen; |
1279 | } | 1279 | } |
1280 | else | 1280 | else |
1281 | { | 1281 | { |
1282 | i = ASN1_get_object(&p, &plen, &ptag, &pclass, len); | 1282 | i = ASN1_get_object(&p, &plen, &ptag, &pclass, len); |
1283 | if (ctx) | 1283 | if (ctx) |
1284 | { | 1284 | { |
1285 | ctx->ret = i; | 1285 | ctx->ret = i; |
1286 | ctx->plen = plen; | 1286 | ctx->plen = plen; |
1287 | ctx->pclass = pclass; | 1287 | ctx->pclass = pclass; |
@@ -1292,25 +1292,25 @@ static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass, | |||
1292 | * header can't exceed total amount of data available. | 1292 | * header can't exceed total amount of data available. |
1293 | */ | 1293 | */ |
1294 | if (!(i & 0x81) && ((plen + ctx->hdrlen) > len)) | 1294 | if (!(i & 0x81) && ((plen + ctx->hdrlen) > len)) |
1295 | { | 1295 | { |
1296 | ASN1err(ASN1_F_ASN1_CHECK_TLEN, | 1296 | ASN1err(ASN1_F_ASN1_CHECK_TLEN, |
1297 | ASN1_R_TOO_LONG); | 1297 | ASN1_R_TOO_LONG); |
1298 | asn1_tlc_clear(ctx); | 1298 | asn1_tlc_clear(ctx); |
1299 | return 0; | 1299 | return 0; |
1300 | } | ||
1301 | } | 1300 | } |
1302 | } | 1301 | } |
1302 | } | ||
1303 | 1303 | ||
1304 | if (i & 0x80) | 1304 | if (i & 0x80) |
1305 | { | 1305 | { |
1306 | ASN1err(ASN1_F_ASN1_CHECK_TLEN, ASN1_R_BAD_OBJECT_HEADER); | 1306 | ASN1err(ASN1_F_ASN1_CHECK_TLEN, ASN1_R_BAD_OBJECT_HEADER); |
1307 | asn1_tlc_clear(ctx); | 1307 | asn1_tlc_clear(ctx); |
1308 | return 0; | 1308 | return 0; |
1309 | } | 1309 | } |
1310 | if (exptag >= 0) | 1310 | if (exptag >= 0) |
1311 | { | 1311 | { |
1312 | if ((exptag != ptag) || (expclass != pclass)) | 1312 | if ((exptag != ptag) || (expclass != pclass)) |
1313 | { | 1313 | { |
1314 | /* If type is OPTIONAL, not an error: | 1314 | /* If type is OPTIONAL, not an error: |
1315 | * indicate missing type. | 1315 | * indicate missing type. |
1316 | */ | 1316 | */ |
@@ -1318,11 +1318,11 @@ static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass, | |||
1318 | asn1_tlc_clear(ctx); | 1318 | asn1_tlc_clear(ctx); |
1319 | ASN1err(ASN1_F_ASN1_CHECK_TLEN, ASN1_R_WRONG_TAG); | 1319 | ASN1err(ASN1_F_ASN1_CHECK_TLEN, ASN1_R_WRONG_TAG); |
1320 | return 0; | 1320 | return 0; |
1321 | } | 1321 | } |
1322 | /* We have a tag and class match: | 1322 | /* We have a tag and class match: |
1323 | * assume we are going to do something with it */ | 1323 | * assume we are going to do something with it */ |
1324 | asn1_tlc_clear(ctx); | 1324 | asn1_tlc_clear(ctx); |
1325 | } | 1325 | } |
1326 | 1326 | ||
1327 | if (i & 1) | 1327 | if (i & 1) |
1328 | plen = len - (p - q); | 1328 | plen = len - (p - q); |
@@ -1344,4 +1344,4 @@ static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass, | |||
1344 | 1344 | ||
1345 | *in = p; | 1345 | *in = p; |
1346 | return 1; | 1346 | return 1; |
1347 | } | 1347 | } |
diff --git a/src/lib/libssl/src/crypto/asn1/tasn_enc.c b/src/lib/libssl/src/crypto/asn1/tasn_enc.c index 54e3f7a94a..230164107d 100644 --- a/src/lib/libssl/src/crypto/asn1/tasn_enc.c +++ b/src/lib/libssl/src/crypto/asn1/tasn_enc.c | |||
@@ -82,14 +82,14 @@ static int asn1_item_flags_i2d(ASN1_VALUE *val, unsigned char **out, | |||
82 | 82 | ||
83 | int ASN1_item_ndef_i2d(ASN1_VALUE *val, unsigned char **out, | 83 | int ASN1_item_ndef_i2d(ASN1_VALUE *val, unsigned char **out, |
84 | const ASN1_ITEM *it) | 84 | const ASN1_ITEM *it) |
85 | { | 85 | { |
86 | return asn1_item_flags_i2d(val, out, it, ASN1_TFLG_NDEF); | 86 | return asn1_item_flags_i2d(val, out, it, ASN1_TFLG_NDEF); |
87 | } | 87 | } |
88 | 88 | ||
89 | int ASN1_item_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it) | 89 | int ASN1_item_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it) |
90 | { | 90 | { |
91 | return asn1_item_flags_i2d(val, out, it, 0); | 91 | return asn1_item_flags_i2d(val, out, it, 0); |
92 | } | 92 | } |
93 | 93 | ||
94 | /* Encode an ASN1 item, this is use by the | 94 | /* Encode an ASN1 item, this is use by the |
95 | * standard 'i2d' function. 'out' points to | 95 | * standard 'i2d' function. 'out' points to |
@@ -102,9 +102,9 @@ int ASN1_item_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it) | |||
102 | 102 | ||
103 | static int asn1_item_flags_i2d(ASN1_VALUE *val, unsigned char **out, | 103 | static int asn1_item_flags_i2d(ASN1_VALUE *val, unsigned char **out, |
104 | const ASN1_ITEM *it, int flags) | 104 | const ASN1_ITEM *it, int flags) |
105 | { | 105 | { |
106 | if (out && !*out) | 106 | if (out && !*out) |
107 | { | 107 | { |
108 | unsigned char *p, *buf; | 108 | unsigned char *p, *buf; |
109 | int len; | 109 | int len; |
110 | len = ASN1_item_ex_i2d(&val, NULL, it, -1, flags); | 110 | len = ASN1_item_ex_i2d(&val, NULL, it, -1, flags); |
@@ -117,10 +117,10 @@ static int asn1_item_flags_i2d(ASN1_VALUE *val, unsigned char **out, | |||
117 | ASN1_item_ex_i2d(&val, &p, it, -1, flags); | 117 | ASN1_item_ex_i2d(&val, &p, it, -1, flags); |
118 | *out = buf; | 118 | *out = buf; |
119 | return len; | 119 | return len; |
120 | } | 120 | } |
121 | 121 | ||
122 | return ASN1_item_ex_i2d(&val, out, it, -1, flags); | 122 | return ASN1_item_ex_i2d(&val, out, it, -1, flags); |
123 | } | 123 | } |
124 | 124 | ||
125 | /* Encode an item, taking care of IMPLICIT tagging (if any). | 125 | /* Encode an item, taking care of IMPLICIT tagging (if any). |
126 | * This function performs the normal item handling: it can be | 126 | * This function performs the normal item handling: it can be |
@@ -129,7 +129,7 @@ static int asn1_item_flags_i2d(ASN1_VALUE *val, unsigned char **out, | |||
129 | 129 | ||
130 | int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, | 130 | int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, |
131 | const ASN1_ITEM *it, int tag, int aclass) | 131 | const ASN1_ITEM *it, int tag, int aclass) |
132 | { | 132 | { |
133 | const ASN1_TEMPLATE *tt = NULL; | 133 | const ASN1_TEMPLATE *tt = NULL; |
134 | unsigned char *p = NULL; | 134 | unsigned char *p = NULL; |
135 | int i, seqcontlen, seqlen, ndef = 1; | 135 | int i, seqcontlen, seqlen, ndef = 1; |
@@ -145,7 +145,7 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, | |||
145 | asn1_cb = aux->asn1_cb; | 145 | asn1_cb = aux->asn1_cb; |
146 | 146 | ||
147 | switch(it->itype) | 147 | switch(it->itype) |
148 | { | 148 | { |
149 | 149 | ||
150 | case ASN1_ITYPE_PRIMITIVE: | 150 | case ASN1_ITYPE_PRIMITIVE: |
151 | if (it->templates) | 151 | if (it->templates) |
@@ -162,14 +162,14 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, | |||
162 | return 0; | 162 | return 0; |
163 | i = asn1_get_choice_selector(pval, it); | 163 | i = asn1_get_choice_selector(pval, it); |
164 | if ((i >= 0) && (i < it->tcount)) | 164 | if ((i >= 0) && (i < it->tcount)) |
165 | { | 165 | { |
166 | ASN1_VALUE **pchval; | 166 | ASN1_VALUE **pchval; |
167 | const ASN1_TEMPLATE *chtt; | 167 | const ASN1_TEMPLATE *chtt; |
168 | chtt = it->templates + i; | 168 | chtt = it->templates + i; |
169 | pchval = asn1_get_field_ptr(pval, chtt); | 169 | pchval = asn1_get_field_ptr(pval, chtt); |
170 | return asn1_template_ex_i2d(pchval, out, chtt, | 170 | return asn1_template_ex_i2d(pchval, out, chtt, |
171 | -1, aclass); | 171 | -1, aclass); |
172 | } | 172 | } |
173 | /* Fixme: error condition if selector out of range */ | 173 | /* Fixme: error condition if selector out of range */ |
174 | if (asn1_cb && !asn1_cb(ASN1_OP_I2D_POST, pval, it, NULL)) | 174 | if (asn1_cb && !asn1_cb(ASN1_OP_I2D_POST, pval, it, NULL)) |
175 | return 0; | 175 | return 0; |
@@ -210,17 +210,17 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, | |||
210 | seqcontlen = 0; | 210 | seqcontlen = 0; |
211 | /* If no IMPLICIT tagging set to SEQUENCE, UNIVERSAL */ | 211 | /* If no IMPLICIT tagging set to SEQUENCE, UNIVERSAL */ |
212 | if (tag == -1) | 212 | if (tag == -1) |
213 | { | 213 | { |
214 | tag = V_ASN1_SEQUENCE; | 214 | tag = V_ASN1_SEQUENCE; |
215 | /* Retain any other flags in aclass */ | 215 | /* Retain any other flags in aclass */ |
216 | aclass = (aclass & ~ASN1_TFLG_TAG_CLASS) | 216 | aclass = (aclass & ~ASN1_TFLG_TAG_CLASS) |
217 | | V_ASN1_UNIVERSAL; | 217 | | V_ASN1_UNIVERSAL; |
218 | } | 218 | } |
219 | if (asn1_cb && !asn1_cb(ASN1_OP_I2D_PRE, pval, it, NULL)) | 219 | if (asn1_cb && !asn1_cb(ASN1_OP_I2D_PRE, pval, it, NULL)) |
220 | return 0; | 220 | return 0; |
221 | /* First work out sequence content length */ | 221 | /* First work out sequence content length */ |
222 | for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) | 222 | for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) |
223 | { | 223 | { |
224 | const ASN1_TEMPLATE *seqtt; | 224 | const ASN1_TEMPLATE *seqtt; |
225 | ASN1_VALUE **pseqval; | 225 | ASN1_VALUE **pseqval; |
226 | seqtt = asn1_do_adb(pval, tt, 1); | 226 | seqtt = asn1_do_adb(pval, tt, 1); |
@@ -230,7 +230,7 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, | |||
230 | /* FIXME: check for errors in enhanced version */ | 230 | /* FIXME: check for errors in enhanced version */ |
231 | seqcontlen += asn1_template_ex_i2d(pseqval, NULL, seqtt, | 231 | seqcontlen += asn1_template_ex_i2d(pseqval, NULL, seqtt, |
232 | -1, aclass); | 232 | -1, aclass); |
233 | } | 233 | } |
234 | 234 | ||
235 | seqlen = ASN1_object_size(ndef, seqcontlen, tag); | 235 | seqlen = ASN1_object_size(ndef, seqcontlen, tag); |
236 | if (!out) | 236 | if (!out) |
@@ -238,7 +238,7 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, | |||
238 | /* Output SEQUENCE header */ | 238 | /* Output SEQUENCE header */ |
239 | ASN1_put_object(out, ndef, seqcontlen, tag, aclass); | 239 | ASN1_put_object(out, ndef, seqcontlen, tag, aclass); |
240 | for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) | 240 | for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) |
241 | { | 241 | { |
242 | const ASN1_TEMPLATE *seqtt; | 242 | const ASN1_TEMPLATE *seqtt; |
243 | ASN1_VALUE **pseqval; | 243 | ASN1_VALUE **pseqval; |
244 | seqtt = asn1_do_adb(pval, tt, 1); | 244 | seqtt = asn1_do_adb(pval, tt, 1); |
@@ -247,7 +247,7 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, | |||
247 | pseqval = asn1_get_field_ptr(pval, seqtt); | 247 | pseqval = asn1_get_field_ptr(pval, seqtt); |
248 | /* FIXME: check for errors in enhanced version */ | 248 | /* FIXME: check for errors in enhanced version */ |
249 | asn1_template_ex_i2d(pseqval, out, seqtt, -1, aclass); | 249 | asn1_template_ex_i2d(pseqval, out, seqtt, -1, aclass); |
250 | } | 250 | } |
251 | if (ndef == 2) | 251 | if (ndef == 2) |
252 | ASN1_put_eoc(out); | 252 | ASN1_put_eoc(out); |
253 | if (asn1_cb && !asn1_cb(ASN1_OP_I2D_POST, pval, it, NULL)) | 253 | if (asn1_cb && !asn1_cb(ASN1_OP_I2D_POST, pval, it, NULL)) |
@@ -257,19 +257,19 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, | |||
257 | default: | 257 | default: |
258 | return 0; | 258 | return 0; |
259 | 259 | ||
260 | } | ||
261 | return 0; | ||
262 | } | 260 | } |
261 | return 0; | ||
262 | } | ||
263 | 263 | ||
264 | int ASN1_template_i2d(ASN1_VALUE **pval, unsigned char **out, | 264 | int ASN1_template_i2d(ASN1_VALUE **pval, unsigned char **out, |
265 | const ASN1_TEMPLATE *tt) | 265 | const ASN1_TEMPLATE *tt) |
266 | { | 266 | { |
267 | return asn1_template_ex_i2d(pval, out, tt, -1, 0); | 267 | return asn1_template_ex_i2d(pval, out, tt, -1, 0); |
268 | } | 268 | } |
269 | 269 | ||
270 | static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out, | 270 | static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out, |
271 | const ASN1_TEMPLATE *tt, int tag, int iclass) | 271 | const ASN1_TEMPLATE *tt, int tag, int iclass) |
272 | { | 272 | { |
273 | int i, ret, flags, ttag, tclass, ndef; | 273 | int i, ret, flags, ttag, tclass, ndef; |
274 | flags = tt->flags; | 274 | flags = tt->flags; |
275 | /* Work out tag and class to use: tagging may come | 275 | /* Work out tag and class to use: tagging may come |
@@ -279,7 +279,7 @@ static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out, | |||
279 | * which should be noted and passed down to other levels. | 279 | * which should be noted and passed down to other levels. |
280 | */ | 280 | */ |
281 | if (flags & ASN1_TFLG_TAG_MASK) | 281 | if (flags & ASN1_TFLG_TAG_MASK) |
282 | { | 282 | { |
283 | /* Error if argument and template tagging */ | 283 | /* Error if argument and template tagging */ |
284 | if (tag != -1) | 284 | if (tag != -1) |
285 | /* FIXME: error code here */ | 285 | /* FIXME: error code here */ |
@@ -287,18 +287,18 @@ static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out, | |||
287 | /* Get tagging from template */ | 287 | /* Get tagging from template */ |
288 | ttag = tt->tag; | 288 | ttag = tt->tag; |
289 | tclass = flags & ASN1_TFLG_TAG_CLASS; | 289 | tclass = flags & ASN1_TFLG_TAG_CLASS; |
290 | } | 290 | } |
291 | else if (tag != -1) | 291 | else if (tag != -1) |
292 | { | 292 | { |
293 | /* No template tagging, get from arguments */ | 293 | /* No template tagging, get from arguments */ |
294 | ttag = tag; | 294 | ttag = tag; |
295 | tclass = iclass & ASN1_TFLG_TAG_CLASS; | 295 | tclass = iclass & ASN1_TFLG_TAG_CLASS; |
296 | } | 296 | } |
297 | else | 297 | else |
298 | { | 298 | { |
299 | ttag = -1; | 299 | ttag = -1; |
300 | tclass = 0; | 300 | tclass = 0; |
301 | } | 301 | } |
302 | /* | 302 | /* |
303 | * Remove any class mask from iflag. | 303 | * Remove any class mask from iflag. |
304 | */ | 304 | */ |
@@ -315,7 +315,7 @@ static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out, | |||
315 | else ndef = 1; | 315 | else ndef = 1; |
316 | 316 | ||
317 | if (flags & ASN1_TFLG_SK_MASK) | 317 | if (flags & ASN1_TFLG_SK_MASK) |
318 | { | 318 | { |
319 | /* SET OF, SEQUENCE OF */ | 319 | /* SET OF, SEQUENCE OF */ |
320 | STACK_OF(ASN1_VALUE) *sk = (STACK_OF(ASN1_VALUE) *)*pval; | 320 | STACK_OF(ASN1_VALUE) *sk = (STACK_OF(ASN1_VALUE) *)*pval; |
321 | int isset, sktag, skaclass; | 321 | int isset, sktag, skaclass; |
@@ -326,39 +326,39 @@ static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out, | |||
326 | return 0; | 326 | return 0; |
327 | 327 | ||
328 | if (flags & ASN1_TFLG_SET_OF) | 328 | if (flags & ASN1_TFLG_SET_OF) |
329 | { | 329 | { |
330 | isset = 1; | 330 | isset = 1; |
331 | /* 2 means we reorder */ | 331 | /* 2 means we reorder */ |
332 | if (flags & ASN1_TFLG_SEQUENCE_OF) | 332 | if (flags & ASN1_TFLG_SEQUENCE_OF) |
333 | isset = 2; | 333 | isset = 2; |
334 | } | 334 | } |
335 | else isset = 0; | 335 | else isset = 0; |
336 | 336 | ||
337 | /* Work out inner tag value: if EXPLICIT | 337 | /* Work out inner tag value: if EXPLICIT |
338 | * or no tagging use underlying type. | 338 | * or no tagging use underlying type. |
339 | */ | 339 | */ |
340 | if ((ttag != -1) && !(flags & ASN1_TFLG_EXPTAG)) | 340 | if ((ttag != -1) && !(flags & ASN1_TFLG_EXPTAG)) |
341 | { | 341 | { |
342 | sktag = ttag; | 342 | sktag = ttag; |
343 | skaclass = tclass; | 343 | skaclass = tclass; |
344 | } | 344 | } |
345 | else | 345 | else |
346 | { | 346 | { |
347 | skaclass = V_ASN1_UNIVERSAL; | 347 | skaclass = V_ASN1_UNIVERSAL; |
348 | if (isset) | 348 | if (isset) |
349 | sktag = V_ASN1_SET; | 349 | sktag = V_ASN1_SET; |
350 | else sktag = V_ASN1_SEQUENCE; | 350 | else sktag = V_ASN1_SEQUENCE; |
351 | } | 351 | } |
352 | 352 | ||
353 | /* Determine total length of items */ | 353 | /* Determine total length of items */ |
354 | skcontlen = 0; | 354 | skcontlen = 0; |
355 | for (i = 0; i < sk_ASN1_VALUE_num(sk); i++) | 355 | for (i = 0; i < sk_ASN1_VALUE_num(sk); i++) |
356 | { | 356 | { |
357 | skitem = sk_ASN1_VALUE_value(sk, i); | 357 | skitem = sk_ASN1_VALUE_value(sk, i); |
358 | skcontlen += ASN1_item_ex_i2d(&skitem, NULL, | 358 | skcontlen += ASN1_item_ex_i2d(&skitem, NULL, |
359 | ASN1_ITEM_ptr(tt->item), | 359 | ASN1_ITEM_ptr(tt->item), |
360 | -1, iclass); | 360 | -1, iclass); |
361 | } | 361 | } |
362 | sklen = ASN1_object_size(ndef, skcontlen, sktag); | 362 | sklen = ASN1_object_size(ndef, skcontlen, sktag); |
363 | /* If EXPLICIT need length of surrounding tag */ | 363 | /* If EXPLICIT need length of surrounding tag */ |
364 | if (flags & ASN1_TFLG_EXPTAG) | 364 | if (flags & ASN1_TFLG_EXPTAG) |
@@ -378,17 +378,17 @@ static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out, | |||
378 | asn1_set_seq_out(sk, out, skcontlen, ASN1_ITEM_ptr(tt->item), | 378 | asn1_set_seq_out(sk, out, skcontlen, ASN1_ITEM_ptr(tt->item), |
379 | isset, iclass); | 379 | isset, iclass); |
380 | if (ndef == 2) | 380 | if (ndef == 2) |
381 | { | 381 | { |
382 | ASN1_put_eoc(out); | 382 | ASN1_put_eoc(out); |
383 | if (flags & ASN1_TFLG_EXPTAG) | 383 | if (flags & ASN1_TFLG_EXPTAG) |
384 | ASN1_put_eoc(out); | 384 | ASN1_put_eoc(out); |
385 | } | 385 | } |
386 | 386 | ||
387 | return ret; | 387 | return ret; |
388 | } | 388 | } |
389 | 389 | ||
390 | if (flags & ASN1_TFLG_EXPTAG) | 390 | if (flags & ASN1_TFLG_EXPTAG) |
391 | { | 391 | { |
392 | /* EXPLICIT tagging */ | 392 | /* EXPLICIT tagging */ |
393 | /* Find length of tagged item */ | 393 | /* Find length of tagged item */ |
394 | i = ASN1_item_ex_i2d(pval, NULL, ASN1_ITEM_ptr(tt->item), | 394 | i = ASN1_item_ex_i2d(pval, NULL, ASN1_ITEM_ptr(tt->item), |
@@ -398,16 +398,16 @@ static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out, | |||
398 | /* Find length of EXPLICIT tag */ | 398 | /* Find length of EXPLICIT tag */ |
399 | ret = ASN1_object_size(ndef, i, ttag); | 399 | ret = ASN1_object_size(ndef, i, ttag); |
400 | if (out) | 400 | if (out) |
401 | { | 401 | { |
402 | /* Output tag and item */ | 402 | /* Output tag and item */ |
403 | ASN1_put_object(out, ndef, i, ttag, tclass); | 403 | ASN1_put_object(out, ndef, i, ttag, tclass); |
404 | ASN1_item_ex_i2d(pval, out, ASN1_ITEM_ptr(tt->item), | 404 | ASN1_item_ex_i2d(pval, out, ASN1_ITEM_ptr(tt->item), |
405 | -1, iclass); | 405 | -1, iclass); |
406 | if (ndef == 2) | 406 | if (ndef == 2) |
407 | ASN1_put_eoc(out); | 407 | ASN1_put_eoc(out); |
408 | } | ||
409 | return ret; | ||
410 | } | 408 | } |
409 | return ret; | ||
410 | } | ||
411 | 411 | ||
412 | /* Either normal or IMPLICIT tagging: combine class and flags */ | 412 | /* Either normal or IMPLICIT tagging: combine class and flags */ |
413 | return ASN1_item_ex_i2d(pval, out, ASN1_ITEM_ptr(tt->item), | 413 | return ASN1_item_ex_i2d(pval, out, ASN1_ITEM_ptr(tt->item), |
@@ -424,7 +424,7 @@ typedef struct { | |||
424 | } DER_ENC; | 424 | } DER_ENC; |
425 | 425 | ||
426 | static int der_cmp(const void *a, const void *b) | 426 | static int der_cmp(const void *a, const void *b) |
427 | { | 427 | { |
428 | const DER_ENC *d1 = a, *d2 = b; | 428 | const DER_ENC *d1 = a, *d2 = b; |
429 | int cmplen, i; | 429 | int cmplen, i; |
430 | cmplen = (d1->length < d2->length) ? d1->length : d2->length; | 430 | cmplen = (d1->length < d2->length) ? d1->length : d2->length; |
@@ -432,14 +432,14 @@ static int der_cmp(const void *a, const void *b) | |||
432 | if (i) | 432 | if (i) |
433 | return i; | 433 | return i; |
434 | return d1->length - d2->length; | 434 | return d1->length - d2->length; |
435 | } | 435 | } |
436 | 436 | ||
437 | /* Output the content octets of SET OF or SEQUENCE OF */ | 437 | /* Output the content octets of SET OF or SEQUENCE OF */ |
438 | 438 | ||
439 | static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out, | 439 | static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out, |
440 | int skcontlen, const ASN1_ITEM *item, | 440 | int skcontlen, const ASN1_ITEM *item, |
441 | int do_sort, int iclass) | 441 | int do_sort, int iclass) |
442 | { | 442 | { |
443 | int i; | 443 | int i; |
444 | ASN1_VALUE *skitem; | 444 | ASN1_VALUE *skitem; |
445 | unsigned char *tmpdat = NULL, *p = NULL; | 445 | unsigned char *tmpdat = NULL, *p = NULL; |
@@ -450,7 +450,7 @@ static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out, | |||
450 | if (sk_ASN1_VALUE_num(sk) < 2) | 450 | if (sk_ASN1_VALUE_num(sk) < 2) |
451 | do_sort = 0; | 451 | do_sort = 0; |
452 | else | 452 | else |
453 | { | 453 | { |
454 | derlst = malloc(sk_ASN1_VALUE_num(sk) | 454 | derlst = malloc(sk_ASN1_VALUE_num(sk) |
455 | * sizeof(*derlst)); | 455 | * sizeof(*derlst)); |
456 | tmpdat = malloc(skcontlen); | 456 | tmpdat = malloc(skcontlen); |
@@ -458,54 +458,54 @@ static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out, | |||
458 | free(derlst); | 458 | free(derlst); |
459 | free(tmpdat); | 459 | free(tmpdat); |
460 | return 0; | 460 | return 0; |
461 | } | ||
462 | } | 461 | } |
462 | } | ||
463 | /* If not sorting just output each item */ | 463 | /* If not sorting just output each item */ |
464 | if (!do_sort) | 464 | if (!do_sort) |
465 | { | 465 | { |
466 | for (i = 0; i < sk_ASN1_VALUE_num(sk); i++) | 466 | for (i = 0; i < sk_ASN1_VALUE_num(sk); i++) |
467 | { | 467 | { |
468 | skitem = sk_ASN1_VALUE_value(sk, i); | 468 | skitem = sk_ASN1_VALUE_value(sk, i); |
469 | ASN1_item_ex_i2d(&skitem, out, item, -1, iclass); | 469 | ASN1_item_ex_i2d(&skitem, out, item, -1, iclass); |
470 | } | ||
471 | return 1; | ||
472 | } | 470 | } |
471 | return 1; | ||
472 | } | ||
473 | p = tmpdat; | 473 | p = tmpdat; |
474 | 474 | ||
475 | /* Doing sort: build up a list of each member's DER encoding */ | 475 | /* Doing sort: build up a list of each member's DER encoding */ |
476 | for (i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++) | 476 | for (i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++) |
477 | { | 477 | { |
478 | skitem = sk_ASN1_VALUE_value(sk, i); | 478 | skitem = sk_ASN1_VALUE_value(sk, i); |
479 | tder->data = p; | 479 | tder->data = p; |
480 | tder->length = ASN1_item_ex_i2d(&skitem, &p, item, -1, iclass); | 480 | tder->length = ASN1_item_ex_i2d(&skitem, &p, item, -1, iclass); |
481 | tder->field = skitem; | 481 | tder->field = skitem; |
482 | } | 482 | } |
483 | 483 | ||
484 | /* Now sort them */ | 484 | /* Now sort them */ |
485 | qsort(derlst, sk_ASN1_VALUE_num(sk), sizeof(*derlst), der_cmp); | 485 | qsort(derlst, sk_ASN1_VALUE_num(sk), sizeof(*derlst), der_cmp); |
486 | /* Output sorted DER encoding */ | 486 | /* Output sorted DER encoding */ |
487 | p = *out; | 487 | p = *out; |
488 | for (i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++) | 488 | for (i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++) |
489 | { | 489 | { |
490 | memcpy(p, tder->data, tder->length); | 490 | memcpy(p, tder->data, tder->length); |
491 | p += tder->length; | 491 | p += tder->length; |
492 | } | 492 | } |
493 | *out = p; | 493 | *out = p; |
494 | /* If do_sort is 2 then reorder the STACK */ | 494 | /* If do_sort is 2 then reorder the STACK */ |
495 | if (do_sort == 2) | 495 | if (do_sort == 2) |
496 | { | 496 | { |
497 | for (i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); | 497 | for (i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); |
498 | i++, tder++) | 498 | i++, tder++) |
499 | (void)sk_ASN1_VALUE_set(sk, i, tder->field); | 499 | (void)sk_ASN1_VALUE_set(sk, i, tder->field); |
500 | } | 500 | } |
501 | free(derlst); | 501 | free(derlst); |
502 | free(tmpdat); | 502 | free(tmpdat); |
503 | return 1; | 503 | return 1; |
504 | } | 504 | } |
505 | 505 | ||
506 | static int asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out, | 506 | static int asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out, |
507 | const ASN1_ITEM *it, int tag, int aclass) | 507 | const ASN1_ITEM *it, int tag, int aclass) |
508 | { | 508 | { |
509 | int len; | 509 | int len; |
510 | int utype; | 510 | int utype; |
511 | int usetag; | 511 | int usetag; |
@@ -537,17 +537,17 @@ static int asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out, | |||
537 | 537 | ||
538 | /* -2 return is special meaning use ndef */ | 538 | /* -2 return is special meaning use ndef */ |
539 | if (len == -2) | 539 | if (len == -2) |
540 | { | 540 | { |
541 | ndef = 2; | 541 | ndef = 2; |
542 | len = 0; | 542 | len = 0; |
543 | } | 543 | } |
544 | 544 | ||
545 | /* If not implicitly tagged get tag from underlying type */ | 545 | /* If not implicitly tagged get tag from underlying type */ |
546 | if (tag == -1) tag = utype; | 546 | if (tag == -1) tag = utype; |
547 | 547 | ||
548 | /* Output tag+length followed by content octets */ | 548 | /* Output tag+length followed by content octets */ |
549 | if (out) | 549 | if (out) |
550 | { | 550 | { |
551 | if (usetag) | 551 | if (usetag) |
552 | ASN1_put_object(out, ndef, len, tag, aclass); | 552 | ASN1_put_object(out, ndef, len, tag, aclass); |
553 | asn1_ex_i2c(pval, *out, &utype, it); | 553 | asn1_ex_i2c(pval, *out, &utype, it); |
@@ -555,18 +555,18 @@ static int asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out, | |||
555 | ASN1_put_eoc(out); | 555 | ASN1_put_eoc(out); |
556 | else | 556 | else |
557 | *out += len; | 557 | *out += len; |
558 | } | 558 | } |
559 | 559 | ||
560 | if (usetag) | 560 | if (usetag) |
561 | return ASN1_object_size(ndef, len, tag); | 561 | return ASN1_object_size(ndef, len, tag); |
562 | return len; | 562 | return len; |
563 | } | 563 | } |
564 | 564 | ||
565 | /* Produce content octets from a structure */ | 565 | /* Produce content octets from a structure */ |
566 | 566 | ||
567 | int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype, | 567 | int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype, |
568 | const ASN1_ITEM *it) | 568 | const ASN1_ITEM *it) |
569 | { | 569 | { |
570 | ASN1_BOOLEAN *tbool = NULL; | 570 | ASN1_BOOLEAN *tbool = NULL; |
571 | ASN1_STRING *strtmp; | 571 | ASN1_STRING *strtmp; |
572 | ASN1_OBJECT *otmp; | 572 | ASN1_OBJECT *otmp; |
@@ -582,30 +582,30 @@ int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype, | |||
582 | /* Should type be omitted? */ | 582 | /* Should type be omitted? */ |
583 | if ((it->itype != ASN1_ITYPE_PRIMITIVE) | 583 | if ((it->itype != ASN1_ITYPE_PRIMITIVE) |
584 | || (it->utype != V_ASN1_BOOLEAN)) | 584 | || (it->utype != V_ASN1_BOOLEAN)) |
585 | { | 585 | { |
586 | if (!*pval) return -1; | 586 | if (!*pval) return -1; |
587 | } | 587 | } |
588 | 588 | ||
589 | if (it->itype == ASN1_ITYPE_MSTRING) | 589 | if (it->itype == ASN1_ITYPE_MSTRING) |
590 | { | 590 | { |
591 | /* If MSTRING type set the underlying type */ | 591 | /* If MSTRING type set the underlying type */ |
592 | strtmp = (ASN1_STRING *)*pval; | 592 | strtmp = (ASN1_STRING *)*pval; |
593 | utype = strtmp->type; | 593 | utype = strtmp->type; |
594 | *putype = utype; | 594 | *putype = utype; |
595 | } | 595 | } |
596 | else if (it->utype == V_ASN1_ANY) | 596 | else if (it->utype == V_ASN1_ANY) |
597 | { | 597 | { |
598 | /* If ANY set type and pointer to value */ | 598 | /* If ANY set type and pointer to value */ |
599 | ASN1_TYPE *typ; | 599 | ASN1_TYPE *typ; |
600 | typ = (ASN1_TYPE *)*pval; | 600 | typ = (ASN1_TYPE *)*pval; |
601 | utype = typ->type; | 601 | utype = typ->type; |
602 | *putype = utype; | 602 | *putype = utype; |
603 | pval = &typ->value.asn1_value; | 603 | pval = &typ->value.asn1_value; |
604 | } | 604 | } |
605 | else utype = *putype; | 605 | else utype = *putype; |
606 | 606 | ||
607 | switch(utype) | 607 | switch(utype) |
608 | { | 608 | { |
609 | case V_ASN1_OBJECT: | 609 | case V_ASN1_OBJECT: |
610 | otmp = (ASN1_OBJECT *)*pval; | 610 | otmp = (ASN1_OBJECT *)*pval; |
611 | cont = otmp->data; | 611 | cont = otmp->data; |
@@ -622,13 +622,13 @@ int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype, | |||
622 | if (*tbool == -1) | 622 | if (*tbool == -1) |
623 | return -1; | 623 | return -1; |
624 | if (it->utype != V_ASN1_ANY) | 624 | if (it->utype != V_ASN1_ANY) |
625 | { | 625 | { |
626 | /* Default handling if value == size field then omit */ | 626 | /* Default handling if value == size field then omit */ |
627 | if (*tbool && (it->size > 0)) | 627 | if (*tbool && (it->size > 0)) |
628 | return -1; | 628 | return -1; |
629 | if (!*tbool && !it->size) | 629 | if (!*tbool && !it->size) |
630 | return -1; | 630 | return -1; |
631 | } | 631 | } |
632 | c = (unsigned char)*tbool; | 632 | c = (unsigned char)*tbool; |
633 | cont = &c; | 633 | cont = &c; |
634 | len = 1; | 634 | len = 1; |
@@ -672,22 +672,22 @@ int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype, | |||
672 | /* Special handling for NDEF */ | 672 | /* Special handling for NDEF */ |
673 | if ((it->size == ASN1_TFLG_NDEF) | 673 | if ((it->size == ASN1_TFLG_NDEF) |
674 | && (strtmp->flags & ASN1_STRING_FLAG_NDEF)) | 674 | && (strtmp->flags & ASN1_STRING_FLAG_NDEF)) |
675 | { | 675 | { |
676 | if (cout) | 676 | if (cout) |
677 | { | 677 | { |
678 | strtmp->data = cout; | 678 | strtmp->data = cout; |
679 | strtmp->length = 0; | 679 | strtmp->length = 0; |
680 | } | 680 | } |
681 | /* Special return code */ | 681 | /* Special return code */ |
682 | return -2; | 682 | return -2; |
683 | } | 683 | } |
684 | cont = strtmp->data; | 684 | cont = strtmp->data; |
685 | len = strtmp->length; | 685 | len = strtmp->length; |
686 | 686 | ||
687 | break; | 687 | break; |
688 | 688 | ||
689 | } | 689 | } |
690 | if (cout && len) | 690 | if (cout && len) |
691 | memcpy(cout, cont, len); | 691 | memcpy(cout, cont, len); |
692 | return len; | 692 | return len; |
693 | } | 693 | } |
diff --git a/src/lib/libssl/src/crypto/asn1/tasn_fre.c b/src/lib/libssl/src/crypto/asn1/tasn_fre.c index b04034ba4c..b321de6615 100644 --- a/src/lib/libssl/src/crypto/asn1/tasn_fre.c +++ b/src/lib/libssl/src/crypto/asn1/tasn_fre.c | |||
@@ -67,17 +67,17 @@ static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int c | |||
67 | /* Free up an ASN1 structure */ | 67 | /* Free up an ASN1 structure */ |
68 | 68 | ||
69 | void ASN1_item_free(ASN1_VALUE *val, const ASN1_ITEM *it) | 69 | void ASN1_item_free(ASN1_VALUE *val, const ASN1_ITEM *it) |
70 | { | 70 | { |
71 | asn1_item_combine_free(&val, it, 0); | 71 | asn1_item_combine_free(&val, it, 0); |
72 | } | 72 | } |
73 | 73 | ||
74 | void ASN1_item_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it) | 74 | void ASN1_item_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it) |
75 | { | 75 | { |
76 | asn1_item_combine_free(pval, it, 0); | 76 | asn1_item_combine_free(pval, it, 0); |
77 | } | 77 | } |
78 | 78 | ||
79 | static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine) | 79 | static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine) |
80 | { | 80 | { |
81 | const ASN1_TEMPLATE *tt = NULL, *seqtt; | 81 | const ASN1_TEMPLATE *tt = NULL, *seqtt; |
82 | const ASN1_EXTERN_FUNCS *ef; | 82 | const ASN1_EXTERN_FUNCS *ef; |
83 | const ASN1_COMPAT_FUNCS *cf; | 83 | const ASN1_COMPAT_FUNCS *cf; |
@@ -94,7 +94,7 @@ static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int c | |||
94 | asn1_cb = 0; | 94 | asn1_cb = 0; |
95 | 95 | ||
96 | switch(it->itype) | 96 | switch(it->itype) |
97 | { | 97 | { |
98 | 98 | ||
99 | case ASN1_ITYPE_PRIMITIVE: | 99 | case ASN1_ITYPE_PRIMITIVE: |
100 | if (it->templates) | 100 | if (it->templates) |
@@ -109,26 +109,26 @@ static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int c | |||
109 | 109 | ||
110 | case ASN1_ITYPE_CHOICE: | 110 | case ASN1_ITYPE_CHOICE: |
111 | if (asn1_cb) | 111 | if (asn1_cb) |
112 | { | 112 | { |
113 | i = asn1_cb(ASN1_OP_FREE_PRE, pval, it, NULL); | 113 | i = asn1_cb(ASN1_OP_FREE_PRE, pval, it, NULL); |
114 | if (i == 2) | 114 | if (i == 2) |
115 | return; | 115 | return; |
116 | } | 116 | } |
117 | i = asn1_get_choice_selector(pval, it); | 117 | i = asn1_get_choice_selector(pval, it); |
118 | if ((i >= 0) && (i < it->tcount)) | 118 | if ((i >= 0) && (i < it->tcount)) |
119 | { | 119 | { |
120 | ASN1_VALUE **pchval; | 120 | ASN1_VALUE **pchval; |
121 | tt = it->templates + i; | 121 | tt = it->templates + i; |
122 | pchval = asn1_get_field_ptr(pval, tt); | 122 | pchval = asn1_get_field_ptr(pval, tt); |
123 | ASN1_template_free(pchval, tt); | 123 | ASN1_template_free(pchval, tt); |
124 | } | 124 | } |
125 | if (asn1_cb) | 125 | if (asn1_cb) |
126 | asn1_cb(ASN1_OP_FREE_POST, pval, it, NULL); | 126 | asn1_cb(ASN1_OP_FREE_POST, pval, it, NULL); |
127 | if (!combine) | 127 | if (!combine) |
128 | { | 128 | { |
129 | free(*pval); | 129 | free(*pval); |
130 | *pval = NULL; | 130 | *pval = NULL; |
131 | } | 131 | } |
132 | break; | 132 | break; |
133 | 133 | ||
134 | case ASN1_ITYPE_COMPAT: | 134 | case ASN1_ITYPE_COMPAT: |
@@ -148,11 +148,11 @@ static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int c | |||
148 | if (asn1_do_lock(pval, -1, it) > 0) | 148 | if (asn1_do_lock(pval, -1, it) > 0) |
149 | return; | 149 | return; |
150 | if (asn1_cb) | 150 | if (asn1_cb) |
151 | { | 151 | { |
152 | i = asn1_cb(ASN1_OP_FREE_PRE, pval, it, NULL); | 152 | i = asn1_cb(ASN1_OP_FREE_PRE, pval, it, NULL); |
153 | if (i == 2) | 153 | if (i == 2) |
154 | return; | 154 | return; |
155 | } | 155 | } |
156 | asn1_enc_free(pval, it); | 156 | asn1_enc_free(pval, it); |
157 | /* If we free up as normal we will invalidate any | 157 | /* If we free up as normal we will invalidate any |
158 | * ANY DEFINED BY field and we wont be able to | 158 | * ANY DEFINED BY field and we wont be able to |
@@ -161,83 +161,83 @@ static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int c | |||
161 | */ | 161 | */ |
162 | tt = it->templates + it->tcount - 1; | 162 | tt = it->templates + it->tcount - 1; |
163 | for (i = 0; i < it->tcount; tt--, i++) | 163 | for (i = 0; i < it->tcount; tt--, i++) |
164 | { | 164 | { |
165 | ASN1_VALUE **pseqval; | 165 | ASN1_VALUE **pseqval; |
166 | seqtt = asn1_do_adb(pval, tt, 0); | 166 | seqtt = asn1_do_adb(pval, tt, 0); |
167 | if (!seqtt) | 167 | if (!seqtt) |
168 | continue; | 168 | continue; |
169 | pseqval = asn1_get_field_ptr(pval, seqtt); | 169 | pseqval = asn1_get_field_ptr(pval, seqtt); |
170 | ASN1_template_free(pseqval, seqtt); | 170 | ASN1_template_free(pseqval, seqtt); |
171 | } | 171 | } |
172 | if (asn1_cb) | 172 | if (asn1_cb) |
173 | asn1_cb(ASN1_OP_FREE_POST, pval, it, NULL); | 173 | asn1_cb(ASN1_OP_FREE_POST, pval, it, NULL); |
174 | if (!combine) | 174 | if (!combine) |
175 | { | 175 | { |
176 | free(*pval); | 176 | free(*pval); |
177 | *pval = NULL; | 177 | *pval = NULL; |
178 | } | ||
179 | break; | ||
180 | } | 178 | } |
179 | break; | ||
181 | } | 180 | } |
181 | } | ||
182 | 182 | ||
183 | void ASN1_template_free(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) | 183 | void ASN1_template_free(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) |
184 | { | 184 | { |
185 | int i; | 185 | int i; |
186 | if (tt->flags & ASN1_TFLG_SK_MASK) | 186 | if (tt->flags & ASN1_TFLG_SK_MASK) |
187 | { | 187 | { |
188 | STACK_OF(ASN1_VALUE) *sk = (STACK_OF(ASN1_VALUE) *)*pval; | 188 | STACK_OF(ASN1_VALUE) *sk = (STACK_OF(ASN1_VALUE) *)*pval; |
189 | for (i = 0; i < sk_ASN1_VALUE_num(sk); i++) | 189 | for (i = 0; i < sk_ASN1_VALUE_num(sk); i++) |
190 | { | 190 | { |
191 | ASN1_VALUE *vtmp; | 191 | ASN1_VALUE *vtmp; |
192 | vtmp = sk_ASN1_VALUE_value(sk, i); | 192 | vtmp = sk_ASN1_VALUE_value(sk, i); |
193 | asn1_item_combine_free(&vtmp, ASN1_ITEM_ptr(tt->item), | 193 | asn1_item_combine_free(&vtmp, ASN1_ITEM_ptr(tt->item), |
194 | 0); | 194 | 0); |
195 | } | 195 | } |
196 | sk_ASN1_VALUE_free(sk); | 196 | sk_ASN1_VALUE_free(sk); |
197 | *pval = NULL; | 197 | *pval = NULL; |
198 | } | 198 | } |
199 | else | 199 | else |
200 | asn1_item_combine_free(pval, ASN1_ITEM_ptr(tt->item), | 200 | asn1_item_combine_free(pval, ASN1_ITEM_ptr(tt->item), |
201 | tt->flags & ASN1_TFLG_COMBINE); | 201 | tt->flags & ASN1_TFLG_COMBINE); |
202 | } | 202 | } |
203 | 203 | ||
204 | void ASN1_primitive_free(ASN1_VALUE **pval, const ASN1_ITEM *it) | 204 | void ASN1_primitive_free(ASN1_VALUE **pval, const ASN1_ITEM *it) |
205 | { | 205 | { |
206 | int utype; | 206 | int utype; |
207 | if (it) | 207 | if (it) |
208 | { | 208 | { |
209 | const ASN1_PRIMITIVE_FUNCS *pf; | 209 | const ASN1_PRIMITIVE_FUNCS *pf; |
210 | pf = it->funcs; | 210 | pf = it->funcs; |
211 | if (pf && pf->prim_free) | 211 | if (pf && pf->prim_free) |
212 | { | 212 | { |
213 | pf->prim_free(pval, it); | 213 | pf->prim_free(pval, it); |
214 | return; | 214 | return; |
215 | } | ||
216 | } | 215 | } |
216 | } | ||
217 | /* Special case: if 'it' is NULL free contents of ASN1_TYPE */ | 217 | /* Special case: if 'it' is NULL free contents of ASN1_TYPE */ |
218 | if (!it) | 218 | if (!it) |
219 | { | 219 | { |
220 | ASN1_TYPE *typ = (ASN1_TYPE *)*pval; | 220 | ASN1_TYPE *typ = (ASN1_TYPE *)*pval; |
221 | utype = typ->type; | 221 | utype = typ->type; |
222 | pval = &typ->value.asn1_value; | 222 | pval = &typ->value.asn1_value; |
223 | if (!*pval) | 223 | if (!*pval) |
224 | return; | 224 | return; |
225 | } | 225 | } |
226 | else if (it->itype == ASN1_ITYPE_MSTRING) | 226 | else if (it->itype == ASN1_ITYPE_MSTRING) |
227 | { | 227 | { |
228 | utype = -1; | 228 | utype = -1; |
229 | if (!*pval) | 229 | if (!*pval) |
230 | return; | 230 | return; |
231 | } | 231 | } |
232 | else | 232 | else |
233 | { | 233 | { |
234 | utype = it->utype; | 234 | utype = it->utype; |
235 | if ((utype != V_ASN1_BOOLEAN) && !*pval) | 235 | if ((utype != V_ASN1_BOOLEAN) && !*pval) |
236 | return; | 236 | return; |
237 | } | 237 | } |
238 | 238 | ||
239 | switch(utype) | 239 | switch(utype) |
240 | { | 240 | { |
241 | case V_ASN1_OBJECT: | 241 | case V_ASN1_OBJECT: |
242 | ASN1_OBJECT_free((ASN1_OBJECT *)*pval); | 242 | ASN1_OBJECT_free((ASN1_OBJECT *)*pval); |
243 | break; | 243 | break; |
@@ -261,6 +261,6 @@ void ASN1_primitive_free(ASN1_VALUE **pval, const ASN1_ITEM *it) | |||
261 | ASN1_STRING_free((ASN1_STRING *)*pval); | 261 | ASN1_STRING_free((ASN1_STRING *)*pval); |
262 | *pval = NULL; | 262 | *pval = NULL; |
263 | break; | 263 | break; |
264 | } | ||
265 | *pval = NULL; | ||
266 | } | 264 | } |
265 | *pval = NULL; | ||
266 | } | ||
diff --git a/src/lib/libssl/src/crypto/asn1/tasn_new.c b/src/lib/libssl/src/crypto/asn1/tasn_new.c index aab9ef08c4..f5d7c690b8 100644 --- a/src/lib/libssl/src/crypto/asn1/tasn_new.c +++ b/src/lib/libssl/src/crypto/asn1/tasn_new.c | |||
@@ -71,23 +71,23 @@ static void asn1_template_clear(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt); | |||
71 | static void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it); | 71 | static void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it); |
72 | 72 | ||
73 | ASN1_VALUE *ASN1_item_new(const ASN1_ITEM *it) | 73 | ASN1_VALUE *ASN1_item_new(const ASN1_ITEM *it) |
74 | { | 74 | { |
75 | ASN1_VALUE *ret = NULL; | 75 | ASN1_VALUE *ret = NULL; |
76 | if (ASN1_item_ex_new(&ret, it) > 0) | 76 | if (ASN1_item_ex_new(&ret, it) > 0) |
77 | return ret; | 77 | return ret; |
78 | return NULL; | 78 | return NULL; |
79 | } | 79 | } |
80 | 80 | ||
81 | /* Allocate an ASN1 structure */ | 81 | /* Allocate an ASN1 structure */ |
82 | 82 | ||
83 | int ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it) | 83 | int ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it) |
84 | { | 84 | { |
85 | return asn1_item_ex_combine_new(pval, it, 0); | 85 | return asn1_item_ex_combine_new(pval, it, 0); |
86 | } | 86 | } |
87 | 87 | ||
88 | static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, | 88 | static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, |
89 | int combine) | 89 | int combine) |
90 | { | 90 | { |
91 | const ASN1_TEMPLATE *tt = NULL; | 91 | const ASN1_TEMPLATE *tt = NULL; |
92 | const ASN1_COMPAT_FUNCS *cf; | 92 | const ASN1_COMPAT_FUNCS *cf; |
93 | const ASN1_EXTERN_FUNCS *ef; | 93 | const ASN1_EXTERN_FUNCS *ef; |
@@ -108,15 +108,15 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, | |||
108 | #endif | 108 | #endif |
109 | 109 | ||
110 | switch(it->itype) | 110 | switch(it->itype) |
111 | { | 111 | { |
112 | 112 | ||
113 | case ASN1_ITYPE_EXTERN: | 113 | case ASN1_ITYPE_EXTERN: |
114 | ef = it->funcs; | 114 | ef = it->funcs; |
115 | if (ef && ef->asn1_ex_new) | 115 | if (ef && ef->asn1_ex_new) |
116 | { | 116 | { |
117 | if (!ef->asn1_ex_new(pval, it)) | 117 | if (!ef->asn1_ex_new(pval, it)) |
118 | goto memerr; | 118 | goto memerr; |
119 | } | 119 | } |
120 | break; | 120 | break; |
121 | 121 | ||
122 | case ASN1_ITYPE_COMPAT: | 122 | case ASN1_ITYPE_COMPAT: |
@@ -125,15 +125,15 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, | |||
125 | *pval = cf->asn1_new(); | 125 | *pval = cf->asn1_new(); |
126 | if (!*pval) | 126 | if (!*pval) |
127 | goto memerr; | 127 | goto memerr; |
128 | } | 128 | } |
129 | break; | 129 | break; |
130 | 130 | ||
131 | case ASN1_ITYPE_PRIMITIVE: | 131 | case ASN1_ITYPE_PRIMITIVE: |
132 | if (it->templates) | 132 | if (it->templates) |
133 | { | 133 | { |
134 | if (!ASN1_template_new(pval, it->templates)) | 134 | if (!ASN1_template_new(pval, it->templates)) |
135 | goto memerr; | 135 | goto memerr; |
136 | } | 136 | } |
137 | else if (!ASN1_primitive_new(pval, it)) | 137 | else if (!ASN1_primitive_new(pval, it)) |
138 | goto memerr; | 138 | goto memerr; |
139 | break; | 139 | break; |
@@ -145,26 +145,26 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, | |||
145 | 145 | ||
146 | case ASN1_ITYPE_CHOICE: | 146 | case ASN1_ITYPE_CHOICE: |
147 | if (asn1_cb) | 147 | if (asn1_cb) |
148 | { | 148 | { |
149 | i = asn1_cb(ASN1_OP_NEW_PRE, pval, it, NULL); | 149 | i = asn1_cb(ASN1_OP_NEW_PRE, pval, it, NULL); |
150 | if (!i) | 150 | if (!i) |
151 | goto auxerr; | 151 | goto auxerr; |
152 | if (i==2) | 152 | if (i==2) |
153 | { | 153 | { |
154 | #ifdef CRYPTO_MDEBUG | 154 | #ifdef CRYPTO_MDEBUG |
155 | if (it->sname) | 155 | if (it->sname) |
156 | CRYPTO_pop_info(); | 156 | CRYPTO_pop_info(); |
157 | #endif | 157 | #endif |
158 | return 1; | 158 | return 1; |
159 | } | ||
160 | } | 159 | } |
160 | } | ||
161 | if (!combine) | 161 | if (!combine) |
162 | { | 162 | { |
163 | *pval = malloc(it->size); | 163 | *pval = malloc(it->size); |
164 | if (!*pval) | 164 | if (!*pval) |
165 | goto memerr; | 165 | goto memerr; |
166 | memset(*pval, 0, it->size); | 166 | memset(*pval, 0, it->size); |
167 | } | 167 | } |
168 | asn1_set_choice_selector(pval, -1, it); | 168 | asn1_set_choice_selector(pval, -1, it); |
169 | if (asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it, NULL)) | 169 | if (asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it, NULL)) |
170 | goto auxerr; | 170 | goto auxerr; |
@@ -173,38 +173,38 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, | |||
173 | case ASN1_ITYPE_NDEF_SEQUENCE: | 173 | case ASN1_ITYPE_NDEF_SEQUENCE: |
174 | case ASN1_ITYPE_SEQUENCE: | 174 | case ASN1_ITYPE_SEQUENCE: |
175 | if (asn1_cb) | 175 | if (asn1_cb) |
176 | { | 176 | { |
177 | i = asn1_cb(ASN1_OP_NEW_PRE, pval, it, NULL); | 177 | i = asn1_cb(ASN1_OP_NEW_PRE, pval, it, NULL); |
178 | if (!i) | 178 | if (!i) |
179 | goto auxerr; | 179 | goto auxerr; |
180 | if (i==2) | 180 | if (i==2) |
181 | { | 181 | { |
182 | #ifdef CRYPTO_MDEBUG | 182 | #ifdef CRYPTO_MDEBUG |
183 | if (it->sname) | 183 | if (it->sname) |
184 | CRYPTO_pop_info(); | 184 | CRYPTO_pop_info(); |
185 | #endif | 185 | #endif |
186 | return 1; | 186 | return 1; |
187 | } | ||
188 | } | 187 | } |
188 | } | ||
189 | if (!combine) | 189 | if (!combine) |
190 | { | 190 | { |
191 | *pval = malloc(it->size); | 191 | *pval = malloc(it->size); |
192 | if (!*pval) | 192 | if (!*pval) |
193 | goto memerr; | 193 | goto memerr; |
194 | memset(*pval, 0, it->size); | 194 | memset(*pval, 0, it->size); |
195 | asn1_do_lock(pval, 0, it); | 195 | asn1_do_lock(pval, 0, it); |
196 | asn1_enc_init(pval, it); | 196 | asn1_enc_init(pval, it); |
197 | } | 197 | } |
198 | for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) | 198 | for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) |
199 | { | 199 | { |
200 | pseqval = asn1_get_field_ptr(pval, tt); | 200 | pseqval = asn1_get_field_ptr(pval, tt); |
201 | if (!ASN1_template_new(pseqval, tt)) | 201 | if (!ASN1_template_new(pseqval, tt)) |
202 | goto memerr; | 202 | goto memerr; |
203 | } | 203 | } |
204 | if (asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it, NULL)) | 204 | if (asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it, NULL)) |
205 | goto auxerr; | 205 | goto auxerr; |
206 | break; | 206 | break; |
207 | } | 207 | } |
208 | #ifdef CRYPTO_MDEBUG | 208 | #ifdef CRYPTO_MDEBUG |
209 | if (it->sname) CRYPTO_pop_info(); | 209 | if (it->sname) CRYPTO_pop_info(); |
210 | #endif | 210 | #endif |
@@ -225,14 +225,14 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, | |||
225 | #endif | 225 | #endif |
226 | return 0; | 226 | return 0; |
227 | 227 | ||
228 | } | 228 | } |
229 | 229 | ||
230 | static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it) | 230 | static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it) |
231 | { | 231 | { |
232 | const ASN1_EXTERN_FUNCS *ef; | 232 | const ASN1_EXTERN_FUNCS *ef; |
233 | 233 | ||
234 | switch(it->itype) | 234 | switch(it->itype) |
235 | { | 235 | { |
236 | 236 | ||
237 | case ASN1_ITYPE_EXTERN: | 237 | case ASN1_ITYPE_EXTERN: |
238 | ef = it->funcs; | 238 | ef = it->funcs; |
@@ -259,45 +259,45 @@ static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it) | |||
259 | case ASN1_ITYPE_NDEF_SEQUENCE: | 259 | case ASN1_ITYPE_NDEF_SEQUENCE: |
260 | *pval = NULL; | 260 | *pval = NULL; |
261 | break; | 261 | break; |
262 | } | ||
263 | } | 262 | } |
263 | } | ||
264 | 264 | ||
265 | 265 | ||
266 | int ASN1_template_new(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) | 266 | int ASN1_template_new(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) |
267 | { | 267 | { |
268 | const ASN1_ITEM *it = ASN1_ITEM_ptr(tt->item); | 268 | const ASN1_ITEM *it = ASN1_ITEM_ptr(tt->item); |
269 | int ret; | 269 | int ret; |
270 | if (tt->flags & ASN1_TFLG_OPTIONAL) | 270 | if (tt->flags & ASN1_TFLG_OPTIONAL) |
271 | { | 271 | { |
272 | asn1_template_clear(pval, tt); | 272 | asn1_template_clear(pval, tt); |
273 | return 1; | 273 | return 1; |
274 | } | 274 | } |
275 | /* If ANY DEFINED BY nothing to do */ | 275 | /* If ANY DEFINED BY nothing to do */ |
276 | 276 | ||
277 | if (tt->flags & ASN1_TFLG_ADB_MASK) | 277 | if (tt->flags & ASN1_TFLG_ADB_MASK) |
278 | { | 278 | { |
279 | *pval = NULL; | 279 | *pval = NULL; |
280 | return 1; | 280 | return 1; |
281 | } | 281 | } |
282 | #ifdef CRYPTO_MDEBUG | 282 | #ifdef CRYPTO_MDEBUG |
283 | if (tt->field_name) | 283 | if (tt->field_name) |
284 | CRYPTO_push_info(tt->field_name); | 284 | CRYPTO_push_info(tt->field_name); |
285 | #endif | 285 | #endif |
286 | /* If SET OF or SEQUENCE OF, its a STACK */ | 286 | /* If SET OF or SEQUENCE OF, its a STACK */ |
287 | if (tt->flags & ASN1_TFLG_SK_MASK) | 287 | if (tt->flags & ASN1_TFLG_SK_MASK) |
288 | { | 288 | { |
289 | STACK_OF(ASN1_VALUE) *skval; | 289 | STACK_OF(ASN1_VALUE) *skval; |
290 | skval = sk_ASN1_VALUE_new_null(); | 290 | skval = sk_ASN1_VALUE_new_null(); |
291 | if (!skval) | 291 | if (!skval) |
292 | { | 292 | { |
293 | ASN1err(ASN1_F_ASN1_TEMPLATE_NEW, ERR_R_MALLOC_FAILURE); | 293 | ASN1err(ASN1_F_ASN1_TEMPLATE_NEW, ERR_R_MALLOC_FAILURE); |
294 | ret = 0; | 294 | ret = 0; |
295 | goto done; | 295 | goto done; |
296 | } | 296 | } |
297 | *pval = (ASN1_VALUE *)skval; | 297 | *pval = (ASN1_VALUE *)skval; |
298 | ret = 1; | 298 | ret = 1; |
299 | goto done; | 299 | goto done; |
300 | } | 300 | } |
301 | /* Otherwise pass it back to the item routine */ | 301 | /* Otherwise pass it back to the item routine */ |
302 | ret = asn1_item_ex_combine_new(pval, it, tt->flags & ASN1_TFLG_COMBINE); | 302 | ret = asn1_item_ex_combine_new(pval, it, tt->flags & ASN1_TFLG_COMBINE); |
303 | done: | 303 | done: |
@@ -306,16 +306,16 @@ int ASN1_template_new(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) | |||
306 | CRYPTO_pop_info(); | 306 | CRYPTO_pop_info(); |
307 | #endif | 307 | #endif |
308 | return ret; | 308 | return ret; |
309 | } | 309 | } |
310 | 310 | ||
311 | static void asn1_template_clear(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) | 311 | static void asn1_template_clear(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) |
312 | { | 312 | { |
313 | /* If ADB or STACK just NULL the field */ | 313 | /* If ADB or STACK just NULL the field */ |
314 | if (tt->flags & (ASN1_TFLG_ADB_MASK|ASN1_TFLG_SK_MASK)) | 314 | if (tt->flags & (ASN1_TFLG_ADB_MASK|ASN1_TFLG_SK_MASK)) |
315 | *pval = NULL; | 315 | *pval = NULL; |
316 | else | 316 | else |
317 | asn1_item_clear(pval, ASN1_ITEM_ptr(tt->item)); | 317 | asn1_item_clear(pval, ASN1_ITEM_ptr(tt->item)); |
318 | } | 318 | } |
319 | 319 | ||
320 | 320 | ||
321 | /* NB: could probably combine most of the real XXX_new() behaviour and junk | 321 | /* NB: could probably combine most of the real XXX_new() behaviour and junk |
@@ -323,24 +323,24 @@ static void asn1_template_clear(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) | |||
323 | */ | 323 | */ |
324 | 324 | ||
325 | int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it) | 325 | int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it) |
326 | { | 326 | { |
327 | ASN1_TYPE *typ; | 327 | ASN1_TYPE *typ; |
328 | ASN1_STRING *str; | 328 | ASN1_STRING *str; |
329 | int utype; | 329 | int utype; |
330 | 330 | ||
331 | if (it && it->funcs) | 331 | if (it && it->funcs) |
332 | { | 332 | { |
333 | const ASN1_PRIMITIVE_FUNCS *pf = it->funcs; | 333 | const ASN1_PRIMITIVE_FUNCS *pf = it->funcs; |
334 | if (pf->prim_new) | 334 | if (pf->prim_new) |
335 | return pf->prim_new(pval, it); | 335 | return pf->prim_new(pval, it); |
336 | } | 336 | } |
337 | 337 | ||
338 | if (!it || (it->itype == ASN1_ITYPE_MSTRING)) | 338 | if (!it || (it->itype == ASN1_ITYPE_MSTRING)) |
339 | utype = -1; | 339 | utype = -1; |
340 | else | 340 | else |
341 | utype = it->utype; | 341 | utype = it->utype; |
342 | switch(utype) | 342 | switch(utype) |
343 | { | 343 | { |
344 | case V_ASN1_OBJECT: | 344 | case V_ASN1_OBJECT: |
345 | *pval = (ASN1_VALUE *)OBJ_nid2obj(NID_undef); | 345 | *pval = (ASN1_VALUE *)OBJ_nid2obj(NID_undef); |
346 | return 1; | 346 | return 1; |
@@ -368,24 +368,24 @@ int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it) | |||
368 | str->flags |= ASN1_STRING_FLAG_MSTRING; | 368 | str->flags |= ASN1_STRING_FLAG_MSTRING; |
369 | *pval = (ASN1_VALUE *)str; | 369 | *pval = (ASN1_VALUE *)str; |
370 | break; | 370 | break; |
371 | } | 371 | } |
372 | if (*pval) | 372 | if (*pval) |
373 | return 1; | 373 | return 1; |
374 | return 0; | 374 | return 0; |
375 | } | 375 | } |
376 | 376 | ||
377 | static void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it) | 377 | static void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it) |
378 | { | 378 | { |
379 | int utype; | 379 | int utype; |
380 | if (it && it->funcs) | 380 | if (it && it->funcs) |
381 | { | 381 | { |
382 | const ASN1_PRIMITIVE_FUNCS *pf = it->funcs; | 382 | const ASN1_PRIMITIVE_FUNCS *pf = it->funcs; |
383 | if (pf->prim_clear) | 383 | if (pf->prim_clear) |
384 | pf->prim_clear(pval, it); | 384 | pf->prim_clear(pval, it); |
385 | else | 385 | else |
386 | *pval = NULL; | 386 | *pval = NULL; |
387 | return; | 387 | return; |
388 | } | 388 | } |
389 | if (!it || (it->itype == ASN1_ITYPE_MSTRING)) | 389 | if (!it || (it->itype == ASN1_ITYPE_MSTRING)) |
390 | utype = -1; | 390 | utype = -1; |
391 | else | 391 | else |
@@ -393,4 +393,4 @@ static void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it) | |||
393 | if (utype == V_ASN1_BOOLEAN) | 393 | if (utype == V_ASN1_BOOLEAN) |
394 | *(ASN1_BOOLEAN *)pval = it->size; | 394 | *(ASN1_BOOLEAN *)pval = it->size; |
395 | else *pval = NULL; | 395 | else *pval = NULL; |
396 | } | 396 | } |
diff --git a/src/lib/libssl/src/crypto/asn1/tasn_prn.c b/src/lib/libssl/src/crypto/asn1/tasn_prn.c index ec524edac8..f62c085f3b 100644 --- a/src/lib/libssl/src/crypto/asn1/tasn_prn.c +++ b/src/lib/libssl/src/crypto/asn1/tasn_prn.c | |||
@@ -73,86 +73,86 @@ | |||
73 | /* ASN1_PCTX routines */ | 73 | /* ASN1_PCTX routines */ |
74 | 74 | ||
75 | ASN1_PCTX default_pctx = | 75 | ASN1_PCTX default_pctx = |
76 | { | 76 | { |
77 | ASN1_PCTX_FLAGS_SHOW_ABSENT, /* flags */ | 77 | ASN1_PCTX_FLAGS_SHOW_ABSENT, /* flags */ |
78 | 0, /* nm_flags */ | 78 | 0, /* nm_flags */ |
79 | 0, /* cert_flags */ | 79 | 0, /* cert_flags */ |
80 | 0, /* oid_flags */ | 80 | 0, /* oid_flags */ |
81 | 0 /* str_flags */ | 81 | 0 /* str_flags */ |
82 | }; | 82 | }; |
83 | 83 | ||
84 | 84 | ||
85 | ASN1_PCTX *ASN1_PCTX_new(void) | 85 | ASN1_PCTX *ASN1_PCTX_new(void) |
86 | { | 86 | { |
87 | ASN1_PCTX *ret; | 87 | ASN1_PCTX *ret; |
88 | ret = malloc(sizeof(ASN1_PCTX)); | 88 | ret = malloc(sizeof(ASN1_PCTX)); |
89 | if (ret == NULL) | 89 | if (ret == NULL) |
90 | { | 90 | { |
91 | ASN1err(ASN1_F_ASN1_PCTX_NEW, ERR_R_MALLOC_FAILURE); | 91 | ASN1err(ASN1_F_ASN1_PCTX_NEW, ERR_R_MALLOC_FAILURE); |
92 | return NULL; | 92 | return NULL; |
93 | } | 93 | } |
94 | ret->flags = 0; | 94 | ret->flags = 0; |
95 | ret->nm_flags = 0; | 95 | ret->nm_flags = 0; |
96 | ret->cert_flags = 0; | 96 | ret->cert_flags = 0; |
97 | ret->oid_flags = 0; | 97 | ret->oid_flags = 0; |
98 | ret->str_flags = 0; | 98 | ret->str_flags = 0; |
99 | return ret; | 99 | return ret; |
100 | } | 100 | } |
101 | 101 | ||
102 | void ASN1_PCTX_free(ASN1_PCTX *p) | 102 | void ASN1_PCTX_free(ASN1_PCTX *p) |
103 | { | 103 | { |
104 | free(p); | 104 | free(p); |
105 | } | 105 | } |
106 | 106 | ||
107 | unsigned long ASN1_PCTX_get_flags(ASN1_PCTX *p) | 107 | unsigned long ASN1_PCTX_get_flags(ASN1_PCTX *p) |
108 | { | 108 | { |
109 | return p->flags; | 109 | return p->flags; |
110 | } | 110 | } |
111 | 111 | ||
112 | void ASN1_PCTX_set_flags(ASN1_PCTX *p, unsigned long flags) | 112 | void ASN1_PCTX_set_flags(ASN1_PCTX *p, unsigned long flags) |
113 | { | 113 | { |
114 | p->flags = flags; | 114 | p->flags = flags; |
115 | } | 115 | } |
116 | 116 | ||
117 | unsigned long ASN1_PCTX_get_nm_flags(ASN1_PCTX *p) | 117 | unsigned long ASN1_PCTX_get_nm_flags(ASN1_PCTX *p) |
118 | { | 118 | { |
119 | return p->nm_flags; | 119 | return p->nm_flags; |
120 | } | 120 | } |
121 | 121 | ||
122 | void ASN1_PCTX_set_nm_flags(ASN1_PCTX *p, unsigned long flags) | 122 | void ASN1_PCTX_set_nm_flags(ASN1_PCTX *p, unsigned long flags) |
123 | { | 123 | { |
124 | p->nm_flags = flags; | 124 | p->nm_flags = flags; |
125 | } | 125 | } |
126 | 126 | ||
127 | unsigned long ASN1_PCTX_get_cert_flags(ASN1_PCTX *p) | 127 | unsigned long ASN1_PCTX_get_cert_flags(ASN1_PCTX *p) |
128 | { | 128 | { |
129 | return p->cert_flags; | 129 | return p->cert_flags; |
130 | } | 130 | } |
131 | 131 | ||
132 | void ASN1_PCTX_set_cert_flags(ASN1_PCTX *p, unsigned long flags) | 132 | void ASN1_PCTX_set_cert_flags(ASN1_PCTX *p, unsigned long flags) |
133 | { | 133 | { |
134 | p->cert_flags = flags; | 134 | p->cert_flags = flags; |
135 | } | 135 | } |
136 | 136 | ||
137 | unsigned long ASN1_PCTX_get_oid_flags(ASN1_PCTX *p) | 137 | unsigned long ASN1_PCTX_get_oid_flags(ASN1_PCTX *p) |
138 | { | 138 | { |
139 | return p->oid_flags; | 139 | return p->oid_flags; |
140 | } | 140 | } |
141 | 141 | ||
142 | void ASN1_PCTX_set_oid_flags(ASN1_PCTX *p, unsigned long flags) | 142 | void ASN1_PCTX_set_oid_flags(ASN1_PCTX *p, unsigned long flags) |
143 | { | 143 | { |
144 | p->oid_flags = flags; | 144 | p->oid_flags = flags; |
145 | } | 145 | } |
146 | 146 | ||
147 | unsigned long ASN1_PCTX_get_str_flags(ASN1_PCTX *p) | 147 | unsigned long ASN1_PCTX_get_str_flags(ASN1_PCTX *p) |
148 | { | 148 | { |
149 | return p->str_flags; | 149 | return p->str_flags; |
150 | } | 150 | } |
151 | 151 | ||
152 | void ASN1_PCTX_set_str_flags(ASN1_PCTX *p, unsigned long flags) | 152 | void ASN1_PCTX_set_str_flags(ASN1_PCTX *p, unsigned long flags) |
153 | { | 153 | { |
154 | p->str_flags = flags; | 154 | p->str_flags = flags; |
155 | } | 155 | } |
156 | 156 | ||
157 | /* Main print routines */ | 157 | /* Main print routines */ |
158 | 158 | ||
@@ -175,7 +175,7 @@ static int asn1_print_fsname(BIO *out, int indent, | |||
175 | 175 | ||
176 | int ASN1_item_print(BIO *out, ASN1_VALUE *ifld, int indent, | 176 | int ASN1_item_print(BIO *out, ASN1_VALUE *ifld, int indent, |
177 | const ASN1_ITEM *it, const ASN1_PCTX *pctx) | 177 | const ASN1_ITEM *it, const ASN1_PCTX *pctx) |
178 | { | 178 | { |
179 | const char *sname; | 179 | const char *sname; |
180 | if (pctx == NULL) | 180 | if (pctx == NULL) |
181 | pctx = &default_pctx; | 181 | pctx = &default_pctx; |
@@ -185,13 +185,13 @@ int ASN1_item_print(BIO *out, ASN1_VALUE *ifld, int indent, | |||
185 | sname = it->sname; | 185 | sname = it->sname; |
186 | return asn1_item_print_ctx(out, &ifld, indent, it, | 186 | return asn1_item_print_ctx(out, &ifld, indent, it, |
187 | NULL, sname, 0, pctx); | 187 | NULL, sname, 0, pctx); |
188 | } | 188 | } |
189 | 189 | ||
190 | static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent, | 190 | static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent, |
191 | const ASN1_ITEM *it, | 191 | const ASN1_ITEM *it, |
192 | const char *fname, const char *sname, | 192 | const char *fname, const char *sname, |
193 | int nohdr, const ASN1_PCTX *pctx) | 193 | int nohdr, const ASN1_PCTX *pctx) |
194 | { | 194 | { |
195 | const ASN1_TEMPLATE *tt; | 195 | const ASN1_TEMPLATE *tt; |
196 | const ASN1_EXTERN_FUNCS *ef; | 196 | const ASN1_EXTERN_FUNCS *ef; |
197 | ASN1_VALUE **tmpfld; | 197 | ASN1_VALUE **tmpfld; |
@@ -200,36 +200,36 @@ static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent, | |||
200 | ASN1_PRINT_ARG parg; | 200 | ASN1_PRINT_ARG parg; |
201 | int i; | 201 | int i; |
202 | if (aux && aux->asn1_cb) | 202 | if (aux && aux->asn1_cb) |
203 | { | 203 | { |
204 | parg.out = out; | 204 | parg.out = out; |
205 | parg.indent = indent; | 205 | parg.indent = indent; |
206 | parg.pctx = pctx; | 206 | parg.pctx = pctx; |
207 | asn1_cb = aux->asn1_cb; | 207 | asn1_cb = aux->asn1_cb; |
208 | } | 208 | } |
209 | else asn1_cb = 0; | 209 | else asn1_cb = 0; |
210 | 210 | ||
211 | if(*fld == NULL) | 211 | if(*fld == NULL) |
212 | { | 212 | { |
213 | if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_ABSENT) | 213 | if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_ABSENT) |
214 | { | 214 | { |
215 | if (!nohdr && !asn1_print_fsname(out, indent, | 215 | if (!nohdr && !asn1_print_fsname(out, indent, |
216 | fname, sname, pctx)) | 216 | fname, sname, pctx)) |
217 | return 0; | 217 | return 0; |
218 | if (BIO_puts(out, "<ABSENT>\n") <= 0) | 218 | if (BIO_puts(out, "<ABSENT>\n") <= 0) |
219 | return 0; | 219 | return 0; |
220 | } | ||
221 | return 1; | ||
222 | } | 220 | } |
221 | return 1; | ||
222 | } | ||
223 | 223 | ||
224 | switch(it->itype) | 224 | switch(it->itype) |
225 | { | 225 | { |
226 | case ASN1_ITYPE_PRIMITIVE: | 226 | case ASN1_ITYPE_PRIMITIVE: |
227 | if(it->templates) | 227 | if(it->templates) |
228 | { | 228 | { |
229 | if (!asn1_template_print_ctx(out, fld, indent, | 229 | if (!asn1_template_print_ctx(out, fld, indent, |
230 | it->templates, pctx)) | 230 | it->templates, pctx)) |
231 | return 0; | 231 | return 0; |
232 | } | 232 | } |
233 | /* fall thru */ | 233 | /* fall thru */ |
234 | case ASN1_ITYPE_MSTRING: | 234 | case ASN1_ITYPE_MSTRING: |
235 | if (!asn1_primitive_print(out, fld, it, | 235 | if (!asn1_primitive_print(out, fld, it, |
@@ -243,14 +243,14 @@ static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent, | |||
243 | /* Use new style print routine if possible */ | 243 | /* Use new style print routine if possible */ |
244 | ef = it->funcs; | 244 | ef = it->funcs; |
245 | if (ef && ef->asn1_ex_print) | 245 | if (ef && ef->asn1_ex_print) |
246 | { | 246 | { |
247 | i = ef->asn1_ex_print(out, fld, indent, "", pctx); | 247 | i = ef->asn1_ex_print(out, fld, indent, "", pctx); |
248 | if (!i) | 248 | if (!i) |
249 | return 0; | 249 | return 0; |
250 | if ((i == 2) && (BIO_puts(out, "\n") <= 0)) | 250 | if ((i == 2) && (BIO_puts(out, "\n") <= 0)) |
251 | return 0; | 251 | return 0; |
252 | return 1; | 252 | return 1; |
253 | } | 253 | } |
254 | else if (sname && | 254 | else if (sname && |
255 | BIO_printf(out, ":EXTERNAL TYPE %s\n", sname) <= 0) | 255 | BIO_printf(out, ":EXTERNAL TYPE %s\n", sname) <= 0) |
256 | return 0; | 256 | return 0; |
@@ -265,12 +265,12 @@ static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent, | |||
265 | i = asn1_get_choice_selector(fld, it); | 265 | i = asn1_get_choice_selector(fld, it); |
266 | /* This should never happen... */ | 266 | /* This should never happen... */ |
267 | if((i < 0) || (i >= it->tcount)) | 267 | if((i < 0) || (i >= it->tcount)) |
268 | { | 268 | { |
269 | if (BIO_printf(out, | 269 | if (BIO_printf(out, |
270 | "ERROR: selector [%d] invalid\n", i) <= 0) | 270 | "ERROR: selector [%d] invalid\n", i) <= 0) |
271 | return 0; | 271 | return 0; |
272 | return 1; | 272 | return 1; |
273 | } | 273 | } |
274 | tt = it->templates + i; | 274 | tt = it->templates + i; |
275 | tmpfld = asn1_get_field_ptr(fld, tt); | 275 | tmpfld = asn1_get_field_ptr(fld, tt); |
276 | if (!asn1_template_print_ctx(out, tmpfld, indent, tt, pctx)) | 276 | if (!asn1_template_print_ctx(out, tmpfld, indent, tt, pctx)) |
@@ -282,63 +282,63 @@ static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent, | |||
282 | if (!nohdr && !asn1_print_fsname(out, indent, fname, sname, pctx)) | 282 | if (!nohdr && !asn1_print_fsname(out, indent, fname, sname, pctx)) |
283 | return 0; | 283 | return 0; |
284 | if (fname || sname) | 284 | if (fname || sname) |
285 | { | 285 | { |
286 | if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_SEQUENCE) | 286 | if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_SEQUENCE) |
287 | { | 287 | { |
288 | if (BIO_puts(out, " {\n") <= 0) | 288 | if (BIO_puts(out, " {\n") <= 0) |
289 | return 0; | 289 | return 0; |
290 | } | 290 | } |
291 | else | 291 | else |
292 | { | 292 | { |
293 | if (BIO_puts(out, "\n") <= 0) | 293 | if (BIO_puts(out, "\n") <= 0) |
294 | return 0; | 294 | return 0; |
295 | } | ||
296 | } | 295 | } |
296 | } | ||
297 | 297 | ||
298 | if (asn1_cb) | 298 | if (asn1_cb) |
299 | { | 299 | { |
300 | i = asn1_cb(ASN1_OP_PRINT_PRE, fld, it, &parg); | 300 | i = asn1_cb(ASN1_OP_PRINT_PRE, fld, it, &parg); |
301 | if (i == 0) | 301 | if (i == 0) |
302 | return 0; | 302 | return 0; |
303 | if (i == 2) | 303 | if (i == 2) |
304 | return 1; | 304 | return 1; |
305 | } | 305 | } |
306 | 306 | ||
307 | /* Print each field entry */ | 307 | /* Print each field entry */ |
308 | for(i = 0, tt = it->templates; i < it->tcount; i++, tt++) | 308 | for(i = 0, tt = it->templates; i < it->tcount; i++, tt++) |
309 | { | 309 | { |
310 | const ASN1_TEMPLATE *seqtt; | 310 | const ASN1_TEMPLATE *seqtt; |
311 | seqtt = asn1_do_adb(fld, tt, 1); | 311 | seqtt = asn1_do_adb(fld, tt, 1); |
312 | tmpfld = asn1_get_field_ptr(fld, seqtt); | 312 | tmpfld = asn1_get_field_ptr(fld, seqtt); |
313 | if (!asn1_template_print_ctx(out, tmpfld, | 313 | if (!asn1_template_print_ctx(out, tmpfld, |
314 | indent + 2, seqtt, pctx)) | 314 | indent + 2, seqtt, pctx)) |
315 | return 0; | 315 | return 0; |
316 | } | 316 | } |
317 | if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_SEQUENCE) | 317 | if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_SEQUENCE) |
318 | { | 318 | { |
319 | if (BIO_printf(out, "%*s}\n", indent, "") < 0) | 319 | if (BIO_printf(out, "%*s}\n", indent, "") < 0) |
320 | return 0; | 320 | return 0; |
321 | } | 321 | } |
322 | 322 | ||
323 | if (asn1_cb) | 323 | if (asn1_cb) |
324 | { | 324 | { |
325 | i = asn1_cb(ASN1_OP_PRINT_POST, fld, it, &parg); | 325 | i = asn1_cb(ASN1_OP_PRINT_POST, fld, it, &parg); |
326 | if (i == 0) | 326 | if (i == 0) |
327 | return 0; | 327 | return 0; |
328 | } | 328 | } |
329 | break; | 329 | break; |
330 | 330 | ||
331 | default: | 331 | default: |
332 | BIO_printf(out, "Unprocessed type %d\n", it->itype); | 332 | BIO_printf(out, "Unprocessed type %d\n", it->itype); |
333 | return 0; | 333 | return 0; |
334 | } | 334 | } |
335 | 335 | ||
336 | return 1; | 336 | return 1; |
337 | } | 337 | } |
338 | 338 | ||
339 | int asn1_template_print_ctx(BIO *out, ASN1_VALUE **fld, int indent, | 339 | int asn1_template_print_ctx(BIO *out, ASN1_VALUE **fld, int indent, |
340 | const ASN1_TEMPLATE *tt, const ASN1_PCTX *pctx) | 340 | const ASN1_TEMPLATE *tt, const ASN1_PCTX *pctx) |
341 | { | 341 | { |
342 | int i, flags; | 342 | int i, flags; |
343 | const char *sname, *fname; | 343 | const char *sname, *fname; |
344 | flags = tt->flags; | 344 | flags = tt->flags; |
@@ -351,16 +351,16 @@ int asn1_template_print_ctx(BIO *out, ASN1_VALUE **fld, int indent, | |||
351 | else | 351 | else |
352 | fname = tt->field_name; | 352 | fname = tt->field_name; |
353 | if(flags & ASN1_TFLG_SK_MASK) | 353 | if(flags & ASN1_TFLG_SK_MASK) |
354 | { | 354 | { |
355 | char *tname; | 355 | char *tname; |
356 | ASN1_VALUE *skitem; | 356 | ASN1_VALUE *skitem; |
357 | STACK_OF(ASN1_VALUE) *stack; | 357 | STACK_OF(ASN1_VALUE) *stack; |
358 | 358 | ||
359 | /* SET OF, SEQUENCE OF */ | 359 | /* SET OF, SEQUENCE OF */ |
360 | if (fname) | 360 | if (fname) |
361 | { | 361 | { |
362 | if(pctx->flags & ASN1_PCTX_FLAGS_SHOW_SSOF) | 362 | if(pctx->flags & ASN1_PCTX_FLAGS_SHOW_SSOF) |
363 | { | 363 | { |
364 | if(flags & ASN1_TFLG_SET_OF) | 364 | if(flags & ASN1_TFLG_SET_OF) |
365 | tname = "SET"; | 365 | tname = "SET"; |
366 | else | 366 | else |
@@ -368,14 +368,14 @@ int asn1_template_print_ctx(BIO *out, ASN1_VALUE **fld, int indent, | |||
368 | if (BIO_printf(out, "%*s%s OF %s {\n", | 368 | if (BIO_printf(out, "%*s%s OF %s {\n", |
369 | indent, "", tname, tt->field_name) <= 0) | 369 | indent, "", tname, tt->field_name) <= 0) |
370 | return 0; | 370 | return 0; |
371 | } | 371 | } |
372 | else if (BIO_printf(out, "%*s%s:\n", indent, "", | 372 | else if (BIO_printf(out, "%*s%s:\n", indent, "", |
373 | fname) <= 0) | 373 | fname) <= 0) |
374 | return 0; | 374 | return 0; |
375 | } | 375 | } |
376 | stack = (STACK_OF(ASN1_VALUE) *)*fld; | 376 | stack = (STACK_OF(ASN1_VALUE) *)*fld; |
377 | for(i = 0; i < sk_ASN1_VALUE_num(stack); i++) | 377 | for(i = 0; i < sk_ASN1_VALUE_num(stack); i++) |
378 | { | 378 | { |
379 | if ((i > 0) && (BIO_puts(out, "\n") <= 0)) | 379 | if ((i > 0) && (BIO_puts(out, "\n") <= 0)) |
380 | return 0; | 380 | return 0; |
381 | 381 | ||
@@ -383,24 +383,24 @@ int asn1_template_print_ctx(BIO *out, ASN1_VALUE **fld, int indent, | |||
383 | if (!asn1_item_print_ctx(out, &skitem, indent + 2, | 383 | if (!asn1_item_print_ctx(out, &skitem, indent + 2, |
384 | ASN1_ITEM_ptr(tt->item), NULL, NULL, 1, pctx)) | 384 | ASN1_ITEM_ptr(tt->item), NULL, NULL, 1, pctx)) |
385 | return 0; | 385 | return 0; |
386 | } | 386 | } |
387 | if (!i && BIO_printf(out, "%*s<EMPTY>\n", indent + 2, "") <= 0) | 387 | if (!i && BIO_printf(out, "%*s<EMPTY>\n", indent + 2, "") <= 0) |
388 | return 0; | 388 | return 0; |
389 | if(pctx->flags & ASN1_PCTX_FLAGS_SHOW_SEQUENCE) | 389 | if(pctx->flags & ASN1_PCTX_FLAGS_SHOW_SEQUENCE) |
390 | { | 390 | { |
391 | if (BIO_printf(out, "%*s}\n", indent, "") <= 0) | 391 | if (BIO_printf(out, "%*s}\n", indent, "") <= 0) |
392 | return 0; | 392 | return 0; |
393 | } | ||
394 | return 1; | ||
395 | } | 393 | } |
394 | return 1; | ||
395 | } | ||
396 | return asn1_item_print_ctx(out, fld, indent, ASN1_ITEM_ptr(tt->item), | 396 | return asn1_item_print_ctx(out, fld, indent, ASN1_ITEM_ptr(tt->item), |
397 | fname, sname, 0, pctx); | 397 | fname, sname, 0, pctx); |
398 | } | 398 | } |
399 | 399 | ||
400 | static int asn1_print_fsname(BIO *out, int indent, | 400 | static int asn1_print_fsname(BIO *out, int indent, |
401 | const char *fname, const char *sname, | 401 | const char *fname, const char *sname, |
402 | const ASN1_PCTX *pctx) | 402 | const ASN1_PCTX *pctx) |
403 | { | 403 | { |
404 | static char spaces[] = " "; | 404 | static char spaces[] = " "; |
405 | const int nspaces = sizeof(spaces) - 1; | 405 | const int nspaces = sizeof(spaces) - 1; |
406 | 406 | ||
@@ -410,11 +410,11 @@ static int asn1_print_fsname(BIO *out, int indent, | |||
410 | #endif | 410 | #endif |
411 | 411 | ||
412 | while (indent > nspaces) | 412 | while (indent > nspaces) |
413 | { | 413 | { |
414 | if (BIO_write(out, spaces, nspaces) != nspaces) | 414 | if (BIO_write(out, spaces, nspaces) != nspaces) |
415 | return 0; | 415 | return 0; |
416 | indent -= nspaces; | 416 | indent -= nspaces; |
417 | } | 417 | } |
418 | if (BIO_write(out, spaces, indent) != indent) | 418 | if (BIO_write(out, spaces, indent) != indent) |
419 | return 0; | 419 | return 0; |
420 | if (pctx->flags & ASN1_PCTX_FLAGS_NO_STRUCT_NAME) | 420 | if (pctx->flags & ASN1_PCTX_FLAGS_NO_STRUCT_NAME) |
@@ -424,34 +424,34 @@ static int asn1_print_fsname(BIO *out, int indent, | |||
424 | if (!sname && !fname) | 424 | if (!sname && !fname) |
425 | return 1; | 425 | return 1; |
426 | if (fname) | 426 | if (fname) |
427 | { | 427 | { |
428 | if (BIO_puts(out, fname) <= 0) | 428 | if (BIO_puts(out, fname) <= 0) |
429 | return 0; | 429 | return 0; |
430 | } | 430 | } |
431 | if (sname) | 431 | if (sname) |
432 | { | 432 | { |
433 | if (fname) | 433 | if (fname) |
434 | { | 434 | { |
435 | if (BIO_printf(out, " (%s)", sname) <= 0) | 435 | if (BIO_printf(out, " (%s)", sname) <= 0) |
436 | return 0; | 436 | return 0; |
437 | } | 437 | } |
438 | else | 438 | else |
439 | { | 439 | { |
440 | if (BIO_puts(out, sname) <= 0) | 440 | if (BIO_puts(out, sname) <= 0) |
441 | return 0; | 441 | return 0; |
442 | } | ||
443 | } | 442 | } |
443 | } | ||
444 | if (BIO_write(out, ": ", 2) != 2) | 444 | if (BIO_write(out, ": ", 2) != 2) |
445 | return 0; | 445 | return 0; |
446 | return 1; | 446 | return 1; |
447 | } | 447 | } |
448 | 448 | ||
449 | static int asn1_print_boolean_ctx(BIO *out, int boolval, | 449 | static int asn1_print_boolean_ctx(BIO *out, int boolval, |
450 | const ASN1_PCTX *pctx) | 450 | const ASN1_PCTX *pctx) |
451 | { | 451 | { |
452 | const char *str; | 452 | const char *str; |
453 | switch (boolval) | 453 | switch (boolval) |
454 | { | 454 | { |
455 | case -1: | 455 | case -1: |
456 | str = "BOOL ABSENT"; | 456 | str = "BOOL ABSENT"; |
457 | break; | 457 | break; |
@@ -464,17 +464,17 @@ static int asn1_print_boolean_ctx(BIO *out, int boolval, | |||
464 | str = "TRUE"; | 464 | str = "TRUE"; |
465 | break; | 465 | break; |
466 | 466 | ||
467 | } | 467 | } |
468 | 468 | ||
469 | if (BIO_puts(out, str) <= 0) | 469 | if (BIO_puts(out, str) <= 0) |
470 | return 0; | 470 | return 0; |
471 | return 1; | 471 | return 1; |
472 | 472 | ||
473 | } | 473 | } |
474 | 474 | ||
475 | static int asn1_print_integer_ctx(BIO *out, ASN1_INTEGER *str, | 475 | static int asn1_print_integer_ctx(BIO *out, ASN1_INTEGER *str, |
476 | const ASN1_PCTX *pctx) | 476 | const ASN1_PCTX *pctx) |
477 | { | 477 | { |
478 | char *s; | 478 | char *s; |
479 | int ret = 1; | 479 | int ret = 1; |
480 | s = i2s_ASN1_INTEGER(NULL, str); | 480 | s = i2s_ASN1_INTEGER(NULL, str); |
@@ -482,11 +482,11 @@ static int asn1_print_integer_ctx(BIO *out, ASN1_INTEGER *str, | |||
482 | ret = 0; | 482 | ret = 0; |
483 | free(s); | 483 | free(s); |
484 | return ret; | 484 | return ret; |
485 | } | 485 | } |
486 | 486 | ||
487 | static int asn1_print_oid_ctx(BIO *out, const ASN1_OBJECT *oid, | 487 | static int asn1_print_oid_ctx(BIO *out, const ASN1_OBJECT *oid, |
488 | const ASN1_PCTX *pctx) | 488 | const ASN1_PCTX *pctx) |
489 | { | 489 | { |
490 | char objbuf[80]; | 490 | char objbuf[80]; |
491 | const char *ln; | 491 | const char *ln; |
492 | ln = OBJ_nid2ln(OBJ_obj2nid(oid)); | 492 | ln = OBJ_nid2ln(OBJ_obj2nid(oid)); |
@@ -496,17 +496,17 @@ static int asn1_print_oid_ctx(BIO *out, const ASN1_OBJECT *oid, | |||
496 | if (BIO_printf(out, "%s (%s)", ln, objbuf) <= 0) | 496 | if (BIO_printf(out, "%s (%s)", ln, objbuf) <= 0) |
497 | return 0; | 497 | return 0; |
498 | return 1; | 498 | return 1; |
499 | } | 499 | } |
500 | 500 | ||
501 | static int asn1_print_obstring_ctx(BIO *out, ASN1_STRING *str, int indent, | 501 | static int asn1_print_obstring_ctx(BIO *out, ASN1_STRING *str, int indent, |
502 | const ASN1_PCTX *pctx) | 502 | const ASN1_PCTX *pctx) |
503 | { | 503 | { |
504 | if (str->type == V_ASN1_BIT_STRING) | 504 | if (str->type == V_ASN1_BIT_STRING) |
505 | { | 505 | { |
506 | if (BIO_printf(out, " (%ld unused bits)\n", | 506 | if (BIO_printf(out, " (%ld unused bits)\n", |
507 | str->flags & 0x7) <= 0) | 507 | str->flags & 0x7) <= 0) |
508 | return 0; | 508 | return 0; |
509 | } | 509 | } |
510 | else if (BIO_puts(out, "\n") <= 0) | 510 | else if (BIO_puts(out, "\n") <= 0) |
511 | return 0; | 511 | return 0; |
512 | if ((str->length > 0) | 512 | if ((str->length > 0) |
@@ -514,13 +514,13 @@ static int asn1_print_obstring_ctx(BIO *out, ASN1_STRING *str, int indent, | |||
514 | indent + 2) <= 0) | 514 | indent + 2) <= 0) |
515 | return 0; | 515 | return 0; |
516 | return 1; | 516 | return 1; |
517 | } | 517 | } |
518 | 518 | ||
519 | static int asn1_primitive_print(BIO *out, ASN1_VALUE **fld, | 519 | static int asn1_primitive_print(BIO *out, ASN1_VALUE **fld, |
520 | const ASN1_ITEM *it, int indent, | 520 | const ASN1_ITEM *it, int indent, |
521 | const char *fname, const char *sname, | 521 | const char *fname, const char *sname, |
522 | const ASN1_PCTX *pctx) | 522 | const ASN1_PCTX *pctx) |
523 | { | 523 | { |
524 | long utype; | 524 | long utype; |
525 | ASN1_STRING *str; | 525 | ASN1_STRING *str; |
526 | int ret = 1, needlf = 1; | 526 | int ret = 1, needlf = 1; |
@@ -537,7 +537,7 @@ static int asn1_primitive_print(BIO *out, ASN1_VALUE **fld, | |||
537 | else | 537 | else |
538 | utype = it->utype; | 538 | utype = it->utype; |
539 | if (utype == V_ASN1_ANY) | 539 | if (utype == V_ASN1_ANY) |
540 | { | 540 | { |
541 | ASN1_TYPE *atype = (ASN1_TYPE *)*fld; | 541 | ASN1_TYPE *atype = (ASN1_TYPE *)*fld; |
542 | utype = atype->type; | 542 | utype = atype->type; |
543 | fld = &atype->value.asn1_value; | 543 | fld = &atype->value.asn1_value; |
@@ -546,39 +546,39 @@ static int asn1_primitive_print(BIO *out, ASN1_VALUE **fld, | |||
546 | pname = NULL; | 546 | pname = NULL; |
547 | else | 547 | else |
548 | pname = ASN1_tag2str(utype); | 548 | pname = ASN1_tag2str(utype); |
549 | } | 549 | } |
550 | else | 550 | else |
551 | { | 551 | { |
552 | if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_TYPE) | 552 | if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_TYPE) |
553 | pname = ASN1_tag2str(utype); | 553 | pname = ASN1_tag2str(utype); |
554 | else | 554 | else |
555 | pname = NULL; | 555 | pname = NULL; |
556 | } | 556 | } |
557 | 557 | ||
558 | if (utype == V_ASN1_NULL) | 558 | if (utype == V_ASN1_NULL) |
559 | { | 559 | { |
560 | if (BIO_puts(out, "NULL\n") <= 0) | 560 | if (BIO_puts(out, "NULL\n") <= 0) |
561 | return 0; | 561 | return 0; |
562 | return 1; | 562 | return 1; |
563 | } | 563 | } |
564 | 564 | ||
565 | if (pname) | 565 | if (pname) |
566 | { | 566 | { |
567 | if (BIO_puts(out, pname) <= 0) | 567 | if (BIO_puts(out, pname) <= 0) |
568 | return 0; | 568 | return 0; |
569 | if (BIO_puts(out, ":") <= 0) | 569 | if (BIO_puts(out, ":") <= 0) |
570 | return 0; | 570 | return 0; |
571 | } | 571 | } |
572 | 572 | ||
573 | switch (utype) | 573 | switch (utype) |
574 | { | 574 | { |
575 | case V_ASN1_BOOLEAN: | 575 | case V_ASN1_BOOLEAN: |
576 | { | 576 | { |
577 | int boolval = *(int *)fld; | 577 | int boolval = *(int *)fld; |
578 | if (boolval == -1) | 578 | if (boolval == -1) |
579 | boolval = it->size; | 579 | boolval = it->size; |
580 | ret = asn1_print_boolean_ctx(out, boolval, pctx); | 580 | ret = asn1_print_boolean_ctx(out, boolval, pctx); |
581 | } | 581 | } |
582 | break; | 582 | break; |
583 | 583 | ||
584 | case V_ASN1_INTEGER: | 584 | case V_ASN1_INTEGER: |
@@ -618,10 +618,10 @@ static int asn1_primitive_print(BIO *out, ASN1_VALUE **fld, | |||
618 | default: | 618 | default: |
619 | ret = ASN1_STRING_print_ex(out, str, pctx->str_flags); | 619 | ret = ASN1_STRING_print_ex(out, str, pctx->str_flags); |
620 | 620 | ||
621 | } | 621 | } |
622 | if (!ret) | 622 | if (!ret) |
623 | return 0; | 623 | return 0; |
624 | if (needlf && BIO_puts(out, "\n") <= 0) | 624 | if (needlf && BIO_puts(out, "\n") <= 0) |
625 | return 0; | 625 | return 0; |
626 | return 1; | 626 | return 1; |
627 | } | 627 | } |
diff --git a/src/lib/libssl/src/crypto/asn1/tasn_utl.c b/src/lib/libssl/src/crypto/asn1/tasn_utl.c index ab4989b6ce..37c86c6af8 100644 --- a/src/lib/libssl/src/crypto/asn1/tasn_utl.c +++ b/src/lib/libssl/src/crypto/asn1/tasn_utl.c | |||
@@ -74,23 +74,23 @@ | |||
74 | */ | 74 | */ |
75 | 75 | ||
76 | int asn1_get_choice_selector(ASN1_VALUE **pval, const ASN1_ITEM *it) | 76 | int asn1_get_choice_selector(ASN1_VALUE **pval, const ASN1_ITEM *it) |
77 | { | 77 | { |
78 | int *sel = offset2ptr(*pval, it->utype); | 78 | int *sel = offset2ptr(*pval, it->utype); |
79 | return *sel; | 79 | return *sel; |
80 | } | 80 | } |
81 | 81 | ||
82 | /* Given an ASN1_ITEM CHOICE type set | 82 | /* Given an ASN1_ITEM CHOICE type set |
83 | * the selector value, return old value. | 83 | * the selector value, return old value. |
84 | */ | 84 | */ |
85 | 85 | ||
86 | int asn1_set_choice_selector(ASN1_VALUE **pval, int value, const ASN1_ITEM *it) | 86 | int asn1_set_choice_selector(ASN1_VALUE **pval, int value, const ASN1_ITEM *it) |
87 | { | 87 | { |
88 | int *sel, ret; | 88 | int *sel, ret; |
89 | sel = offset2ptr(*pval, it->utype); | 89 | sel = offset2ptr(*pval, it->utype); |
90 | ret = *sel; | 90 | ret = *sel; |
91 | *sel = value; | 91 | *sel = value; |
92 | return ret; | 92 | return ret; |
93 | } | 93 | } |
94 | 94 | ||
95 | /* Do reference counting. The value 'op' decides what to do. | 95 | /* Do reference counting. The value 'op' decides what to do. |
96 | * if it is +1 then the count is incremented. If op is 0 count is | 96 | * if it is +1 then the count is incremented. If op is 0 count is |
@@ -99,7 +99,7 @@ int asn1_set_choice_selector(ASN1_VALUE **pval, int value, const ASN1_ITEM *it) | |||
99 | */ | 99 | */ |
100 | 100 | ||
101 | int asn1_do_lock(ASN1_VALUE **pval, int op, const ASN1_ITEM *it) | 101 | int asn1_do_lock(ASN1_VALUE **pval, int op, const ASN1_ITEM *it) |
102 | { | 102 | { |
103 | const ASN1_AUX *aux; | 103 | const ASN1_AUX *aux; |
104 | int *lck, ret; | 104 | int *lck, ret; |
105 | if ((it->itype != ASN1_ITYPE_SEQUENCE) | 105 | if ((it->itype != ASN1_ITYPE_SEQUENCE) |
@@ -110,16 +110,16 @@ int asn1_do_lock(ASN1_VALUE **pval, int op, const ASN1_ITEM *it) | |||
110 | return 0; | 110 | return 0; |
111 | lck = offset2ptr(*pval, aux->ref_offset); | 111 | lck = offset2ptr(*pval, aux->ref_offset); |
112 | if (op == 0) | 112 | if (op == 0) |
113 | { | 113 | { |
114 | *lck = 1; | 114 | *lck = 1; |
115 | return 1; | 115 | return 1; |
116 | } | 116 | } |
117 | ret = CRYPTO_add(lck, op, aux->ref_lock); | 117 | ret = CRYPTO_add(lck, op, aux->ref_lock); |
118 | return ret; | 118 | return ret; |
119 | } | 119 | } |
120 | 120 | ||
121 | static ASN1_ENCODING *asn1_get_enc_ptr(ASN1_VALUE **pval, const ASN1_ITEM *it) | 121 | static ASN1_ENCODING *asn1_get_enc_ptr(ASN1_VALUE **pval, const ASN1_ITEM *it) |
122 | { | 122 | { |
123 | const ASN1_AUX *aux; | 123 | const ASN1_AUX *aux; |
124 | if (!pval || !*pval) | 124 | if (!pval || !*pval) |
125 | return NULL; | 125 | return NULL; |
@@ -127,37 +127,37 @@ static ASN1_ENCODING *asn1_get_enc_ptr(ASN1_VALUE **pval, const ASN1_ITEM *it) | |||
127 | if (!aux || !(aux->flags & ASN1_AFLG_ENCODING)) | 127 | if (!aux || !(aux->flags & ASN1_AFLG_ENCODING)) |
128 | return NULL; | 128 | return NULL; |
129 | return offset2ptr(*pval, aux->enc_offset); | 129 | return offset2ptr(*pval, aux->enc_offset); |
130 | } | 130 | } |
131 | 131 | ||
132 | void asn1_enc_init(ASN1_VALUE **pval, const ASN1_ITEM *it) | 132 | void asn1_enc_init(ASN1_VALUE **pval, const ASN1_ITEM *it) |
133 | { | 133 | { |
134 | ASN1_ENCODING *enc; | 134 | ASN1_ENCODING *enc; |
135 | enc = asn1_get_enc_ptr(pval, it); | 135 | enc = asn1_get_enc_ptr(pval, it); |
136 | if (enc) | 136 | if (enc) |
137 | { | 137 | { |
138 | enc->enc = NULL; | 138 | enc->enc = NULL; |
139 | enc->len = 0; | 139 | enc->len = 0; |
140 | enc->modified = 1; | 140 | enc->modified = 1; |
141 | } | ||
142 | } | 141 | } |
142 | } | ||
143 | 143 | ||
144 | void asn1_enc_free(ASN1_VALUE **pval, const ASN1_ITEM *it) | 144 | void asn1_enc_free(ASN1_VALUE **pval, const ASN1_ITEM *it) |
145 | { | 145 | { |
146 | ASN1_ENCODING *enc; | 146 | ASN1_ENCODING *enc; |
147 | enc = asn1_get_enc_ptr(pval, it); | 147 | enc = asn1_get_enc_ptr(pval, it); |
148 | if (enc) | 148 | if (enc) |
149 | { | 149 | { |
150 | if (enc->enc) | 150 | if (enc->enc) |
151 | free(enc->enc); | 151 | free(enc->enc); |
152 | enc->enc = NULL; | 152 | enc->enc = NULL; |
153 | enc->len = 0; | 153 | enc->len = 0; |
154 | enc->modified = 1; | 154 | enc->modified = 1; |
155 | } | ||
156 | } | 155 | } |
156 | } | ||
157 | 157 | ||
158 | int asn1_enc_save(ASN1_VALUE **pval, const unsigned char *in, int inlen, | 158 | int asn1_enc_save(ASN1_VALUE **pval, const unsigned char *in, int inlen, |
159 | const ASN1_ITEM *it) | 159 | const ASN1_ITEM *it) |
160 | { | 160 | { |
161 | ASN1_ENCODING *enc; | 161 | ASN1_ENCODING *enc; |
162 | enc = asn1_get_enc_ptr(pval, it); | 162 | enc = asn1_get_enc_ptr(pval, it); |
163 | if (!enc) | 163 | if (!enc) |
@@ -173,28 +173,28 @@ int asn1_enc_save(ASN1_VALUE **pval, const unsigned char *in, int inlen, | |||
173 | enc->modified = 0; | 173 | enc->modified = 0; |
174 | 174 | ||
175 | return 1; | 175 | return 1; |
176 | } | 176 | } |
177 | 177 | ||
178 | int asn1_enc_restore(int *len, unsigned char **out, ASN1_VALUE **pval, | 178 | int asn1_enc_restore(int *len, unsigned char **out, ASN1_VALUE **pval, |
179 | const ASN1_ITEM *it) | 179 | const ASN1_ITEM *it) |
180 | { | 180 | { |
181 | ASN1_ENCODING *enc; | 181 | ASN1_ENCODING *enc; |
182 | enc = asn1_get_enc_ptr(pval, it); | 182 | enc = asn1_get_enc_ptr(pval, it); |
183 | if (!enc || enc->modified) | 183 | if (!enc || enc->modified) |
184 | return 0; | 184 | return 0; |
185 | if (out) | 185 | if (out) |
186 | { | 186 | { |
187 | memcpy(*out, enc->enc, enc->len); | 187 | memcpy(*out, enc->enc, enc->len); |
188 | *out += enc->len; | 188 | *out += enc->len; |
189 | } | 189 | } |
190 | if (len) | 190 | if (len) |
191 | *len = enc->len; | 191 | *len = enc->len; |
192 | return 1; | 192 | return 1; |
193 | } | 193 | } |
194 | 194 | ||
195 | /* Given an ASN1_TEMPLATE get a pointer to a field */ | 195 | /* Given an ASN1_TEMPLATE get a pointer to a field */ |
196 | ASN1_VALUE ** asn1_get_field_ptr(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) | 196 | ASN1_VALUE ** asn1_get_field_ptr(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) |
197 | { | 197 | { |
198 | ASN1_VALUE **pvaltmp; | 198 | ASN1_VALUE **pvaltmp; |
199 | if (tt->flags & ASN1_TFLG_COMBINE) | 199 | if (tt->flags & ASN1_TFLG_COMBINE) |
200 | return pval; | 200 | return pval; |
@@ -204,7 +204,7 @@ ASN1_VALUE ** asn1_get_field_ptr(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) | |||
204 | * (int *). | 204 | * (int *). |
205 | */ | 205 | */ |
206 | return pvaltmp; | 206 | return pvaltmp; |
207 | } | 207 | } |
208 | 208 | ||
209 | /* Handle ANY DEFINED BY template, find the selector, look up | 209 | /* Handle ANY DEFINED BY template, find the selector, look up |
210 | * the relevant ASN1_TEMPLATE in the table and return it. | 210 | * the relevant ASN1_TEMPLATE in the table and return it. |
@@ -212,7 +212,7 @@ ASN1_VALUE ** asn1_get_field_ptr(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) | |||
212 | 212 | ||
213 | const ASN1_TEMPLATE *asn1_do_adb(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt, | 213 | const ASN1_TEMPLATE *asn1_do_adb(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt, |
214 | int nullerr) | 214 | int nullerr) |
215 | { | 215 | { |
216 | const ASN1_ADB *adb; | 216 | const ASN1_ADB *adb; |
217 | const ASN1_ADB_TABLE *atbl; | 217 | const ASN1_ADB_TABLE *atbl; |
218 | long selector; | 218 | long selector; |
@@ -229,11 +229,11 @@ const ASN1_TEMPLATE *asn1_do_adb(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt, | |||
229 | 229 | ||
230 | /* Check if NULL */ | 230 | /* Check if NULL */ |
231 | if (!sfld) | 231 | if (!sfld) |
232 | { | 232 | { |
233 | if (!adb->null_tt) | 233 | if (!adb->null_tt) |
234 | goto err; | 234 | goto err; |
235 | return adb->null_tt; | 235 | return adb->null_tt; |
236 | } | 236 | } |
237 | 237 | ||
238 | /* Convert type to a long: | 238 | /* Convert type to a long: |
239 | * NB: don't check for NID_undef here because it | 239 | * NB: don't check for NID_undef here because it |
@@ -269,4 +269,4 @@ const ASN1_TEMPLATE *asn1_do_adb(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt, | |||
269 | ASN1err(ASN1_F_ASN1_DO_ADB, | 269 | ASN1err(ASN1_F_ASN1_DO_ADB, |
270 | ASN1_R_UNSUPPORTED_ANY_DEFINED_BY_TYPE); | 270 | ASN1_R_UNSUPPORTED_ANY_DEFINED_BY_TYPE); |
271 | return NULL; | 271 | return NULL; |
272 | } | 272 | } |
diff --git a/src/lib/libssl/src/crypto/asn1/x_algor.c b/src/lib/libssl/src/crypto/asn1/x_algor.c index 274e456c73..6f6fbb112a 100644 --- a/src/lib/libssl/src/crypto/asn1/x_algor.c +++ b/src/lib/libssl/src/crypto/asn1/x_algor.c | |||
@@ -78,60 +78,60 @@ IMPLEMENT_STACK_OF(X509_ALGOR) | |||
78 | IMPLEMENT_ASN1_SET_OF(X509_ALGOR) | 78 | IMPLEMENT_ASN1_SET_OF(X509_ALGOR) |
79 | 79 | ||
80 | int X509_ALGOR_set0(X509_ALGOR *alg, ASN1_OBJECT *aobj, int ptype, void *pval) | 80 | int X509_ALGOR_set0(X509_ALGOR *alg, ASN1_OBJECT *aobj, int ptype, void *pval) |
81 | { | 81 | { |
82 | if (!alg) | 82 | if (!alg) |
83 | return 0; | 83 | return 0; |
84 | if (ptype != V_ASN1_UNDEF) | 84 | if (ptype != V_ASN1_UNDEF) |
85 | { | 85 | { |
86 | if (alg->parameter == NULL) | 86 | if (alg->parameter == NULL) |
87 | alg->parameter = ASN1_TYPE_new(); | 87 | alg->parameter = ASN1_TYPE_new(); |
88 | if (alg->parameter == NULL) | 88 | if (alg->parameter == NULL) |
89 | return 0; | 89 | return 0; |
90 | } | 90 | } |
91 | if (alg) | 91 | if (alg) |
92 | { | 92 | { |
93 | if (alg->algorithm) | 93 | if (alg->algorithm) |
94 | ASN1_OBJECT_free(alg->algorithm); | 94 | ASN1_OBJECT_free(alg->algorithm); |
95 | alg->algorithm = aobj; | 95 | alg->algorithm = aobj; |
96 | } | 96 | } |
97 | if (ptype == 0) | 97 | if (ptype == 0) |
98 | return 1; | 98 | return 1; |
99 | if (ptype == V_ASN1_UNDEF) | 99 | if (ptype == V_ASN1_UNDEF) |
100 | { | 100 | { |
101 | if (alg->parameter) | 101 | if (alg->parameter) |
102 | { | 102 | { |
103 | ASN1_TYPE_free(alg->parameter); | 103 | ASN1_TYPE_free(alg->parameter); |
104 | alg->parameter = NULL; | 104 | alg->parameter = NULL; |
105 | } | ||
106 | } | 105 | } |
106 | } | ||
107 | else | 107 | else |
108 | ASN1_TYPE_set(alg->parameter, ptype, pval); | 108 | ASN1_TYPE_set(alg->parameter, ptype, pval); |
109 | return 1; | 109 | return 1; |
110 | } | 110 | } |
111 | 111 | ||
112 | void X509_ALGOR_get0(ASN1_OBJECT **paobj, int *pptype, void **ppval, | 112 | void X509_ALGOR_get0(ASN1_OBJECT **paobj, int *pptype, void **ppval, |
113 | X509_ALGOR *algor) | 113 | X509_ALGOR *algor) |
114 | { | 114 | { |
115 | if (paobj) | 115 | if (paobj) |
116 | *paobj = algor->algorithm; | 116 | *paobj = algor->algorithm; |
117 | if (pptype) | 117 | if (pptype) |
118 | { | 118 | { |
119 | if (algor->parameter == NULL) | 119 | if (algor->parameter == NULL) |
120 | { | 120 | { |
121 | *pptype = V_ASN1_UNDEF; | 121 | *pptype = V_ASN1_UNDEF; |
122 | return; | 122 | return; |
123 | } | 123 | } |
124 | else | 124 | else |
125 | *pptype = algor->parameter->type; | 125 | *pptype = algor->parameter->type; |
126 | if (ppval) | 126 | if (ppval) |
127 | *ppval = algor->parameter->value.ptr; | 127 | *ppval = algor->parameter->value.ptr; |
128 | } | ||
129 | } | 128 | } |
129 | } | ||
130 | 130 | ||
131 | /* Set up an X509_ALGOR DigestAlgorithmIdentifier from an EVP_MD */ | 131 | /* Set up an X509_ALGOR DigestAlgorithmIdentifier from an EVP_MD */ |
132 | 132 | ||
133 | void X509_ALGOR_set_md(X509_ALGOR *alg, const EVP_MD *md) | 133 | void X509_ALGOR_set_md(X509_ALGOR *alg, const EVP_MD *md) |
134 | { | 134 | { |
135 | int param_type; | 135 | int param_type; |
136 | 136 | ||
137 | if (md->flags & EVP_MD_FLAG_DIGALGID_ABSENT) | 137 | if (md->flags & EVP_MD_FLAG_DIGALGID_ABSENT) |
@@ -141,4 +141,4 @@ void X509_ALGOR_set_md(X509_ALGOR *alg, const EVP_MD *md) | |||
141 | 141 | ||
142 | X509_ALGOR_set0(alg, OBJ_nid2obj(EVP_MD_type(md)), param_type, NULL); | 142 | X509_ALGOR_set0(alg, OBJ_nid2obj(EVP_MD_type(md)), param_type, NULL); |
143 | 143 | ||
144 | } | 144 | } |
diff --git a/src/lib/libssl/src/crypto/asn1/x_attrib.c b/src/lib/libssl/src/crypto/asn1/x_attrib.c index 1e3713f18f..e620e1224e 100644 --- a/src/lib/libssl/src/crypto/asn1/x_attrib.c +++ b/src/lib/libssl/src/crypto/asn1/x_attrib.c | |||
@@ -97,7 +97,7 @@ IMPLEMENT_ASN1_FUNCTIONS(X509_ATTRIBUTE) | |||
97 | IMPLEMENT_ASN1_DUP_FUNCTION(X509_ATTRIBUTE) | 97 | IMPLEMENT_ASN1_DUP_FUNCTION(X509_ATTRIBUTE) |
98 | 98 | ||
99 | X509_ATTRIBUTE *X509_ATTRIBUTE_create(int nid, int atrtype, void *value) | 99 | X509_ATTRIBUTE *X509_ATTRIBUTE_create(int nid, int atrtype, void *value) |
100 | { | 100 | { |
101 | X509_ATTRIBUTE *ret=NULL; | 101 | X509_ATTRIBUTE *ret=NULL; |
102 | ASN1_TYPE *val=NULL; | 102 | ASN1_TYPE *val=NULL; |
103 | 103 | ||
@@ -115,4 +115,4 @@ err: | |||
115 | if (ret != NULL) X509_ATTRIBUTE_free(ret); | 115 | if (ret != NULL) X509_ATTRIBUTE_free(ret); |
116 | if (val != NULL) ASN1_TYPE_free(val); | 116 | if (val != NULL) ASN1_TYPE_free(val); |
117 | return(NULL); | 117 | return(NULL); |
118 | } | 118 | } |
diff --git a/src/lib/libssl/src/crypto/asn1/x_crl.c b/src/lib/libssl/src/crypto/asn1/x_crl.c index cf7e69aaaf..b3a6355795 100644 --- a/src/lib/libssl/src/crypto/asn1/x_crl.c +++ b/src/lib/libssl/src/crypto/asn1/x_crl.c | |||
@@ -78,12 +78,12 @@ static int def_crl_lookup(X509_CRL *crl, | |||
78 | X509_REVOKED **ret, ASN1_INTEGER *serial, X509_NAME *issuer); | 78 | X509_REVOKED **ret, ASN1_INTEGER *serial, X509_NAME *issuer); |
79 | 79 | ||
80 | static X509_CRL_METHOD int_crl_meth = | 80 | static X509_CRL_METHOD int_crl_meth = |
81 | { | 81 | { |
82 | 0, | 82 | 0, |
83 | 0,0, | 83 | 0,0, |
84 | def_crl_lookup, | 84 | def_crl_lookup, |
85 | def_crl_verify | 85 | def_crl_verify |
86 | }; | 86 | }; |
87 | 87 | ||
88 | static const X509_CRL_METHOD *default_crl_method = &int_crl_meth; | 88 | static const X509_CRL_METHOD *default_crl_method = &int_crl_meth; |
89 | 89 | ||
@@ -104,7 +104,7 @@ static int crl_inf_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, | |||
104 | case ASN1_OP_D2I_POST: | 104 | case ASN1_OP_D2I_POST: |
105 | (void)sk_X509_REVOKED_set_cmp_func(a->revoked,X509_REVOKED_cmp); | 105 | (void)sk_X509_REVOKED_set_cmp_func(a->revoked,X509_REVOKED_cmp); |
106 | break; | 106 | break; |
107 | } | 107 | } |
108 | return 1; | 108 | return 1; |
109 | } | 109 | } |
110 | 110 | ||
@@ -124,7 +124,7 @@ ASN1_SEQUENCE_enc(X509_CRL_INFO, enc, crl_inf_cb) = { | |||
124 | */ | 124 | */ |
125 | 125 | ||
126 | static int crl_set_issuers(X509_CRL *crl) | 126 | static int crl_set_issuers(X509_CRL *crl) |
127 | { | 127 | { |
128 | 128 | ||
129 | int i, j; | 129 | int i, j; |
130 | GENERAL_NAMES *gens, *gtmp; | 130 | GENERAL_NAMES *gens, *gtmp; |
@@ -134,7 +134,7 @@ static int crl_set_issuers(X509_CRL *crl) | |||
134 | 134 | ||
135 | gens = NULL; | 135 | gens = NULL; |
136 | for (i = 0; i < sk_X509_REVOKED_num(revoked); i++) | 136 | for (i = 0; i < sk_X509_REVOKED_num(revoked); i++) |
137 | { | 137 | { |
138 | X509_REVOKED *rev = sk_X509_REVOKED_value(revoked, i); | 138 | X509_REVOKED *rev = sk_X509_REVOKED_value(revoked, i); |
139 | STACK_OF(X509_EXTENSION) *exts; | 139 | STACK_OF(X509_EXTENSION) *exts; |
140 | ASN1_ENUMERATED *reason; | 140 | ASN1_ENUMERATED *reason; |
@@ -143,38 +143,38 @@ static int crl_set_issuers(X509_CRL *crl) | |||
143 | NID_certificate_issuer, | 143 | NID_certificate_issuer, |
144 | &j, NULL); | 144 | &j, NULL); |
145 | if (!gtmp && (j != -1)) | 145 | if (!gtmp && (j != -1)) |
146 | { | 146 | { |
147 | crl->flags |= EXFLAG_INVALID; | 147 | crl->flags |= EXFLAG_INVALID; |
148 | return 1; | 148 | return 1; |
149 | } | 149 | } |
150 | 150 | ||
151 | if (gtmp) | 151 | if (gtmp) |
152 | { | 152 | { |
153 | gens = gtmp; | 153 | gens = gtmp; |
154 | if (!crl->issuers) | 154 | if (!crl->issuers) |
155 | { | 155 | { |
156 | crl->issuers = sk_GENERAL_NAMES_new_null(); | 156 | crl->issuers = sk_GENERAL_NAMES_new_null(); |
157 | if (!crl->issuers) | 157 | if (!crl->issuers) |
158 | return 0; | 158 | return 0; |
159 | } | 159 | } |
160 | if (!sk_GENERAL_NAMES_push(crl->issuers, gtmp)) | 160 | if (!sk_GENERAL_NAMES_push(crl->issuers, gtmp)) |
161 | return 0; | 161 | return 0; |
162 | } | 162 | } |
163 | rev->issuer = gens; | 163 | rev->issuer = gens; |
164 | 164 | ||
165 | reason = X509_REVOKED_get_ext_d2i(rev, NID_crl_reason, | 165 | reason = X509_REVOKED_get_ext_d2i(rev, NID_crl_reason, |
166 | &j, NULL); | 166 | &j, NULL); |
167 | if (!reason && (j != -1)) | 167 | if (!reason && (j != -1)) |
168 | { | 168 | { |
169 | crl->flags |= EXFLAG_INVALID; | 169 | crl->flags |= EXFLAG_INVALID; |
170 | return 1; | 170 | return 1; |
171 | } | 171 | } |
172 | 172 | ||
173 | if (reason) | 173 | if (reason) |
174 | { | 174 | { |
175 | rev->reason = ASN1_ENUMERATED_get(reason); | 175 | rev->reason = ASN1_ENUMERATED_get(reason); |
176 | ASN1_ENUMERATED_free(reason); | 176 | ASN1_ENUMERATED_free(reason); |
177 | } | 177 | } |
178 | else | 178 | else |
179 | rev->reason = CRL_REASON_NONE; | 179 | rev->reason = CRL_REASON_NONE; |
180 | 180 | ||
@@ -183,38 +183,38 @@ static int crl_set_issuers(X509_CRL *crl) | |||
183 | exts = rev->extensions; | 183 | exts = rev->extensions; |
184 | 184 | ||
185 | for (j = 0; j < sk_X509_EXTENSION_num(exts); j++) | 185 | for (j = 0; j < sk_X509_EXTENSION_num(exts); j++) |
186 | { | 186 | { |
187 | ext = sk_X509_EXTENSION_value(exts, j); | 187 | ext = sk_X509_EXTENSION_value(exts, j); |
188 | if (ext->critical > 0) | 188 | if (ext->critical > 0) |
189 | { | 189 | { |
190 | if (OBJ_obj2nid(ext->object) == | 190 | if (OBJ_obj2nid(ext->object) == |
191 | NID_certificate_issuer) | 191 | NID_certificate_issuer) |
192 | continue; | 192 | continue; |
193 | crl->flags |= EXFLAG_CRITICAL; | 193 | crl->flags |= EXFLAG_CRITICAL; |
194 | break; | 194 | break; |
195 | } | ||
196 | } | 195 | } |
196 | } | ||
197 | 197 | ||
198 | 198 | ||
199 | } | 199 | } |
200 | 200 | ||
201 | return 1; | 201 | return 1; |
202 | 202 | ||
203 | } | 203 | } |
204 | 204 | ||
205 | /* The X509_CRL structure needs a bit of customisation. Cache some extensions | 205 | /* The X509_CRL structure needs a bit of customisation. Cache some extensions |
206 | * and hash of the whole CRL. | 206 | * and hash of the whole CRL. |
207 | */ | 207 | */ |
208 | static int crl_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, | 208 | static int crl_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, |
209 | void *exarg) | 209 | void *exarg) |
210 | { | 210 | { |
211 | X509_CRL *crl = (X509_CRL *)*pval; | 211 | X509_CRL *crl = (X509_CRL *)*pval; |
212 | STACK_OF(X509_EXTENSION) *exts; | 212 | STACK_OF(X509_EXTENSION) *exts; |
213 | X509_EXTENSION *ext; | 213 | X509_EXTENSION *ext; |
214 | int idx; | 214 | int idx; |
215 | 215 | ||
216 | switch(operation) | 216 | switch(operation) |
217 | { | 217 | { |
218 | case ASN1_OP_NEW_POST: | 218 | case ASN1_OP_NEW_POST: |
219 | crl->idp = NULL; | 219 | crl->idp = NULL; |
220 | crl->akid = NULL; | 220 | crl->akid = NULL; |
@@ -260,40 +260,40 @@ static int crl_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, | |||
260 | exts = crl->crl->extensions; | 260 | exts = crl->crl->extensions; |
261 | 261 | ||
262 | for (idx = 0; idx < sk_X509_EXTENSION_num(exts); idx++) | 262 | for (idx = 0; idx < sk_X509_EXTENSION_num(exts); idx++) |
263 | { | 263 | { |
264 | int nid; | 264 | int nid; |
265 | ext = sk_X509_EXTENSION_value(exts, idx); | 265 | ext = sk_X509_EXTENSION_value(exts, idx); |
266 | nid = OBJ_obj2nid(ext->object); | 266 | nid = OBJ_obj2nid(ext->object); |
267 | if (nid == NID_freshest_crl) | 267 | if (nid == NID_freshest_crl) |
268 | crl->flags |= EXFLAG_FRESHEST; | 268 | crl->flags |= EXFLAG_FRESHEST; |
269 | if (ext->critical > 0) | 269 | if (ext->critical > 0) |
270 | { | 270 | { |
271 | /* We handle IDP and deltas */ | 271 | /* We handle IDP and deltas */ |
272 | if ((nid == NID_issuing_distribution_point) | 272 | if ((nid == NID_issuing_distribution_point) |
273 | || (nid == NID_delta_crl)) | 273 | || (nid == NID_delta_crl)) |
274 | break;; | 274 | break;; |
275 | crl->flags |= EXFLAG_CRITICAL; | 275 | crl->flags |= EXFLAG_CRITICAL; |
276 | break; | 276 | break; |
277 | } | ||
278 | } | 277 | } |
278 | } | ||
279 | 279 | ||
280 | 280 | ||
281 | if (!crl_set_issuers(crl)) | 281 | if (!crl_set_issuers(crl)) |
282 | return 0; | 282 | return 0; |
283 | 283 | ||
284 | if (crl->meth->crl_init) | 284 | if (crl->meth->crl_init) |
285 | { | 285 | { |
286 | if (crl->meth->crl_init(crl) == 0) | 286 | if (crl->meth->crl_init(crl) == 0) |
287 | return 0; | 287 | return 0; |
288 | } | 288 | } |
289 | break; | 289 | break; |
290 | 290 | ||
291 | case ASN1_OP_FREE_POST: | 291 | case ASN1_OP_FREE_POST: |
292 | if (crl->meth->crl_free) | 292 | if (crl->meth->crl_free) |
293 | { | 293 | { |
294 | if (!crl->meth->crl_free(crl)) | 294 | if (!crl->meth->crl_free(crl)) |
295 | return 0; | 295 | return 0; |
296 | } | 296 | } |
297 | if (crl->akid) | 297 | if (crl->akid) |
298 | AUTHORITY_KEYID_free(crl->akid); | 298 | AUTHORITY_KEYID_free(crl->akid); |
299 | if (crl->idp) | 299 | if (crl->idp) |
@@ -302,32 +302,32 @@ static int crl_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, | |||
302 | ASN1_INTEGER_free(crl->base_crl_number); | 302 | ASN1_INTEGER_free(crl->base_crl_number); |
303 | sk_GENERAL_NAMES_pop_free(crl->issuers, GENERAL_NAMES_free); | 303 | sk_GENERAL_NAMES_pop_free(crl->issuers, GENERAL_NAMES_free); |
304 | break; | 304 | break; |
305 | } | ||
306 | return 1; | ||
307 | } | 305 | } |
306 | return 1; | ||
307 | } | ||
308 | 308 | ||
309 | /* Convert IDP into a more convenient form */ | 309 | /* Convert IDP into a more convenient form */ |
310 | 310 | ||
311 | static void setup_idp(X509_CRL *crl, ISSUING_DIST_POINT *idp) | 311 | static void setup_idp(X509_CRL *crl, ISSUING_DIST_POINT *idp) |
312 | { | 312 | { |
313 | int idp_only = 0; | 313 | int idp_only = 0; |
314 | /* Set various flags according to IDP */ | 314 | /* Set various flags according to IDP */ |
315 | crl->idp_flags |= IDP_PRESENT; | 315 | crl->idp_flags |= IDP_PRESENT; |
316 | if (idp->onlyuser > 0) | 316 | if (idp->onlyuser > 0) |
317 | { | 317 | { |
318 | idp_only++; | 318 | idp_only++; |
319 | crl->idp_flags |= IDP_ONLYUSER; | 319 | crl->idp_flags |= IDP_ONLYUSER; |
320 | } | 320 | } |
321 | if (idp->onlyCA > 0) | 321 | if (idp->onlyCA > 0) |
322 | { | 322 | { |
323 | idp_only++; | 323 | idp_only++; |
324 | crl->idp_flags |= IDP_ONLYCA; | 324 | crl->idp_flags |= IDP_ONLYCA; |
325 | } | 325 | } |
326 | if (idp->onlyattr > 0) | 326 | if (idp->onlyattr > 0) |
327 | { | 327 | { |
328 | idp_only++; | 328 | idp_only++; |
329 | crl->idp_flags |= IDP_ONLYATTR; | 329 | crl->idp_flags |= IDP_ONLYATTR; |
330 | } | 330 | } |
331 | 331 | ||
332 | if (idp_only > 1) | 332 | if (idp_only > 1) |
333 | crl->idp_flags |= IDP_INVALID; | 333 | crl->idp_flags |= IDP_INVALID; |
@@ -336,7 +336,7 @@ static void setup_idp(X509_CRL *crl, ISSUING_DIST_POINT *idp) | |||
336 | crl->idp_flags |= IDP_INDIRECT; | 336 | crl->idp_flags |= IDP_INDIRECT; |
337 | 337 | ||
338 | if (idp->onlysomereasons) | 338 | if (idp->onlysomereasons) |
339 | { | 339 | { |
340 | crl->idp_flags |= IDP_REASONS; | 340 | crl->idp_flags |= IDP_REASONS; |
341 | if (idp->onlysomereasons->length > 0) | 341 | if (idp->onlysomereasons->length > 0) |
342 | crl->idp_reasons = idp->onlysomereasons->data[0]; | 342 | crl->idp_reasons = idp->onlysomereasons->data[0]; |
@@ -344,10 +344,10 @@ static void setup_idp(X509_CRL *crl, ISSUING_DIST_POINT *idp) | |||
344 | crl->idp_reasons |= | 344 | crl->idp_reasons |= |
345 | (idp->onlysomereasons->data[1] << 8); | 345 | (idp->onlysomereasons->data[1] << 8); |
346 | crl->idp_reasons &= CRLDP_ALL_REASONS; | 346 | crl->idp_reasons &= CRLDP_ALL_REASONS; |
347 | } | 347 | } |
348 | 348 | ||
349 | DIST_POINT_set_dpname(idp->distpoint, X509_CRL_get_issuer(crl)); | 349 | DIST_POINT_set_dpname(idp->distpoint, X509_CRL_get_issuer(crl)); |
350 | } | 350 | } |
351 | 351 | ||
352 | ASN1_SEQUENCE_ref(X509_CRL, crl_cb, CRYPTO_LOCK_X509_CRL) = { | 352 | ASN1_SEQUENCE_ref(X509_CRL, crl_cb, CRYPTO_LOCK_X509_CRL) = { |
353 | ASN1_SIMPLE(X509_CRL, crl, X509_CRL_INFO), | 353 | ASN1_SIMPLE(X509_CRL, crl, X509_CRL_INFO), |
@@ -362,11 +362,11 @@ IMPLEMENT_ASN1_DUP_FUNCTION(X509_CRL) | |||
362 | 362 | ||
363 | static int X509_REVOKED_cmp(const X509_REVOKED * const *a, | 363 | static int X509_REVOKED_cmp(const X509_REVOKED * const *a, |
364 | const X509_REVOKED * const *b) | 364 | const X509_REVOKED * const *b) |
365 | { | 365 | { |
366 | return(ASN1_STRING_cmp( | 366 | return(ASN1_STRING_cmp( |
367 | (ASN1_STRING *)(*a)->serialNumber, | 367 | (ASN1_STRING *)(*a)->serialNumber, |
368 | (ASN1_STRING *)(*b)->serialNumber)); | 368 | (ASN1_STRING *)(*b)->serialNumber)); |
369 | } | 369 | } |
370 | 370 | ||
371 | int X509_CRL_add0_revoked(X509_CRL *crl, X509_REVOKED *rev) | 371 | int X509_CRL_add0_revoked(X509_CRL *crl, X509_REVOKED *rev) |
372 | { | 372 | { |
@@ -377,73 +377,73 @@ int X509_CRL_add0_revoked(X509_CRL *crl, X509_REVOKED *rev) | |||
377 | if(!inf->revoked || !sk_X509_REVOKED_push(inf->revoked, rev)) { | 377 | if(!inf->revoked || !sk_X509_REVOKED_push(inf->revoked, rev)) { |
378 | ASN1err(ASN1_F_X509_CRL_ADD0_REVOKED, ERR_R_MALLOC_FAILURE); | 378 | ASN1err(ASN1_F_X509_CRL_ADD0_REVOKED, ERR_R_MALLOC_FAILURE); |
379 | return 0; | 379 | return 0; |
380 | } | 380 | } |
381 | inf->enc.modified = 1; | 381 | inf->enc.modified = 1; |
382 | return 1; | 382 | return 1; |
383 | } | 383 | } |
384 | 384 | ||
385 | int X509_CRL_verify(X509_CRL *crl, EVP_PKEY *r) | 385 | int X509_CRL_verify(X509_CRL *crl, EVP_PKEY *r) |
386 | { | 386 | { |
387 | if (crl->meth->crl_verify) | 387 | if (crl->meth->crl_verify) |
388 | return crl->meth->crl_verify(crl, r); | 388 | return crl->meth->crl_verify(crl, r); |
389 | return 0; | 389 | return 0; |
390 | } | 390 | } |
391 | 391 | ||
392 | int X509_CRL_get0_by_serial(X509_CRL *crl, | 392 | int X509_CRL_get0_by_serial(X509_CRL *crl, |
393 | X509_REVOKED **ret, ASN1_INTEGER *serial) | 393 | X509_REVOKED **ret, ASN1_INTEGER *serial) |
394 | { | 394 | { |
395 | if (crl->meth->crl_lookup) | 395 | if (crl->meth->crl_lookup) |
396 | return crl->meth->crl_lookup(crl, ret, serial, NULL); | 396 | return crl->meth->crl_lookup(crl, ret, serial, NULL); |
397 | return 0; | 397 | return 0; |
398 | } | 398 | } |
399 | 399 | ||
400 | int X509_CRL_get0_by_cert(X509_CRL *crl, X509_REVOKED **ret, X509 *x) | 400 | int X509_CRL_get0_by_cert(X509_CRL *crl, X509_REVOKED **ret, X509 *x) |
401 | { | 401 | { |
402 | if (crl->meth->crl_lookup) | 402 | if (crl->meth->crl_lookup) |
403 | return crl->meth->crl_lookup(crl, ret, | 403 | return crl->meth->crl_lookup(crl, ret, |
404 | X509_get_serialNumber(x), | 404 | X509_get_serialNumber(x), |
405 | X509_get_issuer_name(x)); | 405 | X509_get_issuer_name(x)); |
406 | return 0; | 406 | return 0; |
407 | } | 407 | } |
408 | 408 | ||
409 | static int def_crl_verify(X509_CRL *crl, EVP_PKEY *r) | 409 | static int def_crl_verify(X509_CRL *crl, EVP_PKEY *r) |
410 | { | 410 | { |
411 | return(ASN1_item_verify(ASN1_ITEM_rptr(X509_CRL_INFO), | 411 | return(ASN1_item_verify(ASN1_ITEM_rptr(X509_CRL_INFO), |
412 | crl->sig_alg, crl->signature,crl->crl,r)); | 412 | crl->sig_alg, crl->signature,crl->crl,r)); |
413 | } | 413 | } |
414 | 414 | ||
415 | static int crl_revoked_issuer_match(X509_CRL *crl, X509_NAME *nm, | 415 | static int crl_revoked_issuer_match(X509_CRL *crl, X509_NAME *nm, |
416 | X509_REVOKED *rev) | 416 | X509_REVOKED *rev) |
417 | { | 417 | { |
418 | int i; | 418 | int i; |
419 | 419 | ||
420 | if (!rev->issuer) | 420 | if (!rev->issuer) |
421 | { | 421 | { |
422 | if (!nm) | 422 | if (!nm) |
423 | return 1; | 423 | return 1; |
424 | if (!X509_NAME_cmp(nm, X509_CRL_get_issuer(crl))) | 424 | if (!X509_NAME_cmp(nm, X509_CRL_get_issuer(crl))) |
425 | return 1; | 425 | return 1; |
426 | return 0; | 426 | return 0; |
427 | } | 427 | } |
428 | 428 | ||
429 | if (!nm) | 429 | if (!nm) |
430 | nm = X509_CRL_get_issuer(crl); | 430 | nm = X509_CRL_get_issuer(crl); |
431 | 431 | ||
432 | for (i = 0; i < sk_GENERAL_NAME_num(rev->issuer); i++) | 432 | for (i = 0; i < sk_GENERAL_NAME_num(rev->issuer); i++) |
433 | { | 433 | { |
434 | GENERAL_NAME *gen = sk_GENERAL_NAME_value(rev->issuer, i); | 434 | GENERAL_NAME *gen = sk_GENERAL_NAME_value(rev->issuer, i); |
435 | if (gen->type != GEN_DIRNAME) | 435 | if (gen->type != GEN_DIRNAME) |
436 | continue; | 436 | continue; |
437 | if (!X509_NAME_cmp(nm, gen->d.directoryName)) | 437 | if (!X509_NAME_cmp(nm, gen->d.directoryName)) |
438 | return 1; | 438 | return 1; |
439 | } | 439 | } |
440 | return 0; | 440 | return 0; |
441 | 441 | ||
442 | } | 442 | } |
443 | 443 | ||
444 | static int def_crl_lookup(X509_CRL *crl, | 444 | static int def_crl_lookup(X509_CRL *crl, |
445 | X509_REVOKED **ret, ASN1_INTEGER *serial, X509_NAME *issuer) | 445 | X509_REVOKED **ret, ASN1_INTEGER *serial, X509_NAME *issuer) |
446 | { | 446 | { |
447 | X509_REVOKED rtmp, *rev; | 447 | X509_REVOKED rtmp, *rev; |
448 | int idx; | 448 | int idx; |
449 | rtmp.serialNumber = serial; | 449 | rtmp.serialNumber = serial; |
@@ -451,39 +451,39 @@ static int def_crl_lookup(X509_CRL *crl, | |||
451 | * Do this under a lock to avoid race condition. | 451 | * Do this under a lock to avoid race condition. |
452 | */ | 452 | */ |
453 | if (!sk_X509_REVOKED_is_sorted(crl->crl->revoked)) | 453 | if (!sk_X509_REVOKED_is_sorted(crl->crl->revoked)) |
454 | { | 454 | { |
455 | CRYPTO_w_lock(CRYPTO_LOCK_X509_CRL); | 455 | CRYPTO_w_lock(CRYPTO_LOCK_X509_CRL); |
456 | sk_X509_REVOKED_sort(crl->crl->revoked); | 456 | sk_X509_REVOKED_sort(crl->crl->revoked); |
457 | CRYPTO_w_unlock(CRYPTO_LOCK_X509_CRL); | 457 | CRYPTO_w_unlock(CRYPTO_LOCK_X509_CRL); |
458 | } | 458 | } |
459 | idx = sk_X509_REVOKED_find(crl->crl->revoked, &rtmp); | 459 | idx = sk_X509_REVOKED_find(crl->crl->revoked, &rtmp); |
460 | if(idx < 0) | 460 | if(idx < 0) |
461 | return 0; | 461 | return 0; |
462 | /* Need to look for matching name */ | 462 | /* Need to look for matching name */ |
463 | for(;idx < sk_X509_REVOKED_num(crl->crl->revoked); idx++) | 463 | for(;idx < sk_X509_REVOKED_num(crl->crl->revoked); idx++) |
464 | { | 464 | { |
465 | rev = sk_X509_REVOKED_value(crl->crl->revoked, idx); | 465 | rev = sk_X509_REVOKED_value(crl->crl->revoked, idx); |
466 | if (ASN1_INTEGER_cmp(rev->serialNumber, serial)) | 466 | if (ASN1_INTEGER_cmp(rev->serialNumber, serial)) |
467 | return 0; | 467 | return 0; |
468 | if (crl_revoked_issuer_match(crl, issuer, rev)) | 468 | if (crl_revoked_issuer_match(crl, issuer, rev)) |
469 | { | 469 | { |
470 | if (ret) | 470 | if (ret) |
471 | *ret = rev; | 471 | *ret = rev; |
472 | if (rev->reason == CRL_REASON_REMOVE_FROM_CRL) | 472 | if (rev->reason == CRL_REASON_REMOVE_FROM_CRL) |
473 | return 2; | 473 | return 2; |
474 | return 1; | 474 | return 1; |
475 | } | ||
476 | } | 475 | } |
477 | return 0; | ||
478 | } | 476 | } |
477 | return 0; | ||
478 | } | ||
479 | 479 | ||
480 | void X509_CRL_set_default_method(const X509_CRL_METHOD *meth) | 480 | void X509_CRL_set_default_method(const X509_CRL_METHOD *meth) |
481 | { | 481 | { |
482 | if (meth == NULL) | 482 | if (meth == NULL) |
483 | default_crl_method = &int_crl_meth; | 483 | default_crl_method = &int_crl_meth; |
484 | else | 484 | else |
485 | default_crl_method = meth; | 485 | default_crl_method = meth; |
486 | } | 486 | } |
487 | 487 | ||
488 | X509_CRL_METHOD *X509_CRL_METHOD_new( | 488 | X509_CRL_METHOD *X509_CRL_METHOD_new( |
489 | int (*crl_init)(X509_CRL *crl), | 489 | int (*crl_init)(X509_CRL *crl), |
@@ -491,7 +491,7 @@ X509_CRL_METHOD *X509_CRL_METHOD_new( | |||
491 | int (*crl_lookup)(X509_CRL *crl, X509_REVOKED **ret, | 491 | int (*crl_lookup)(X509_CRL *crl, X509_REVOKED **ret, |
492 | ASN1_INTEGER *ser, X509_NAME *issuer), | 492 | ASN1_INTEGER *ser, X509_NAME *issuer), |
493 | int (*crl_verify)(X509_CRL *crl, EVP_PKEY *pk)) | 493 | int (*crl_verify)(X509_CRL *crl, EVP_PKEY *pk)) |
494 | { | 494 | { |
495 | X509_CRL_METHOD *m; | 495 | X509_CRL_METHOD *m; |
496 | m = malloc(sizeof(X509_CRL_METHOD)); | 496 | m = malloc(sizeof(X509_CRL_METHOD)); |
497 | if (!m) | 497 | if (!m) |
@@ -502,24 +502,24 @@ X509_CRL_METHOD *X509_CRL_METHOD_new( | |||
502 | m->crl_verify = crl_verify; | 502 | m->crl_verify = crl_verify; |
503 | m->flags = X509_CRL_METHOD_DYNAMIC; | 503 | m->flags = X509_CRL_METHOD_DYNAMIC; |
504 | return m; | 504 | return m; |
505 | } | 505 | } |
506 | 506 | ||
507 | void X509_CRL_METHOD_free(X509_CRL_METHOD *m) | 507 | void X509_CRL_METHOD_free(X509_CRL_METHOD *m) |
508 | { | 508 | { |
509 | if (!(m->flags & X509_CRL_METHOD_DYNAMIC)) | 509 | if (!(m->flags & X509_CRL_METHOD_DYNAMIC)) |
510 | return; | 510 | return; |
511 | free(m); | 511 | free(m); |
512 | } | 512 | } |
513 | 513 | ||
514 | void X509_CRL_set_meth_data(X509_CRL *crl, void *dat) | 514 | void X509_CRL_set_meth_data(X509_CRL *crl, void *dat) |
515 | { | 515 | { |
516 | crl->meth_data = dat; | 516 | crl->meth_data = dat; |
517 | } | 517 | } |
518 | 518 | ||
519 | void *X509_CRL_get_meth_data(X509_CRL *crl) | 519 | void *X509_CRL_get_meth_data(X509_CRL *crl) |
520 | { | 520 | { |
521 | return crl->meth_data; | 521 | return crl->meth_data; |
522 | } | 522 | } |
523 | 523 | ||
524 | IMPLEMENT_STACK_OF(X509_REVOKED) | 524 | IMPLEMENT_STACK_OF(X509_REVOKED) |
525 | IMPLEMENT_ASN1_SET_OF(X509_REVOKED) | 525 | IMPLEMENT_ASN1_SET_OF(X509_REVOKED) |
diff --git a/src/lib/libssl/src/crypto/asn1/x_info.c b/src/lib/libssl/src/crypto/asn1/x_info.c index cb5b6634a1..c1b6058d58 100644 --- a/src/lib/libssl/src/crypto/asn1/x_info.c +++ b/src/lib/libssl/src/crypto/asn1/x_info.c | |||
@@ -63,15 +63,15 @@ | |||
63 | #include <openssl/x509.h> | 63 | #include <openssl/x509.h> |
64 | 64 | ||
65 | X509_INFO *X509_INFO_new(void) | 65 | X509_INFO *X509_INFO_new(void) |
66 | { | 66 | { |
67 | X509_INFO *ret=NULL; | 67 | X509_INFO *ret=NULL; |
68 | 68 | ||
69 | ret=(X509_INFO *)malloc(sizeof(X509_INFO)); | 69 | ret=(X509_INFO *)malloc(sizeof(X509_INFO)); |
70 | if (ret == NULL) | 70 | if (ret == NULL) |
71 | { | 71 | { |
72 | ASN1err(ASN1_F_X509_INFO_NEW,ERR_R_MALLOC_FAILURE); | 72 | ASN1err(ASN1_F_X509_INFO_NEW,ERR_R_MALLOC_FAILURE); |
73 | return(NULL); | 73 | return(NULL); |
74 | } | 74 | } |
75 | 75 | ||
76 | ret->enc_cipher.cipher=NULL; | 76 | ret->enc_cipher.cipher=NULL; |
77 | ret->enc_len=0; | 77 | ret->enc_len=0; |
@@ -82,10 +82,10 @@ X509_INFO *X509_INFO_new(void) | |||
82 | ret->crl=NULL; | 82 | ret->crl=NULL; |
83 | ret->x_pkey=NULL; | 83 | ret->x_pkey=NULL; |
84 | return(ret); | 84 | return(ret); |
85 | } | 85 | } |
86 | 86 | ||
87 | void X509_INFO_free(X509_INFO *x) | 87 | void X509_INFO_free(X509_INFO *x) |
88 | { | 88 | { |
89 | int i; | 89 | int i; |
90 | 90 | ||
91 | if (x == NULL) return; | 91 | if (x == NULL) return; |
@@ -98,7 +98,7 @@ void X509_INFO_free(X509_INFO *x) | |||
98 | if (x->x_pkey != NULL) X509_PKEY_free(x->x_pkey); | 98 | if (x->x_pkey != NULL) X509_PKEY_free(x->x_pkey); |
99 | if (x->enc_data != NULL) free(x->enc_data); | 99 | if (x->enc_data != NULL) free(x->enc_data); |
100 | free(x); | 100 | free(x); |
101 | } | 101 | } |
102 | 102 | ||
103 | IMPLEMENT_STACK_OF(X509_INFO) | 103 | IMPLEMENT_STACK_OF(X509_INFO) |
104 | 104 | ||
diff --git a/src/lib/libssl/src/crypto/asn1/x_long.c b/src/lib/libssl/src/crypto/asn1/x_long.c index 75317418e1..1417284d3c 100644 --- a/src/lib/libssl/src/crypto/asn1/x_long.c +++ b/src/lib/libssl/src/crypto/asn1/x_long.c | |||
@@ -174,6 +174,6 @@ static int long_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, | |||
174 | 174 | ||
175 | static int long_print(BIO *out, ASN1_VALUE **pval, const ASN1_ITEM *it, | 175 | static int long_print(BIO *out, ASN1_VALUE **pval, const ASN1_ITEM *it, |
176 | int indent, const ASN1_PCTX *pctx) | 176 | int indent, const ASN1_PCTX *pctx) |
177 | { | 177 | { |
178 | return BIO_printf(out, "%ld\n", *(long *)pval); | 178 | return BIO_printf(out, "%ld\n", *(long *)pval); |
179 | } | 179 | } |
diff --git a/src/lib/libssl/src/crypto/asn1/x_name.c b/src/lib/libssl/src/crypto/asn1/x_name.c index e14d329639..dfd4363aa0 100644 --- a/src/lib/libssl/src/crypto/asn1/x_name.c +++ b/src/lib/libssl/src/crypto/asn1/x_name.c | |||
@@ -146,11 +146,11 @@ static int x509_name_ex_new(ASN1_VALUE **val, const ASN1_ITEM *it) | |||
146 | memerr: | 146 | memerr: |
147 | ASN1err(ASN1_F_X509_NAME_EX_NEW, ERR_R_MALLOC_FAILURE); | 147 | ASN1err(ASN1_F_X509_NAME_EX_NEW, ERR_R_MALLOC_FAILURE); |
148 | if (ret) | 148 | if (ret) |
149 | { | 149 | { |
150 | if (ret->entries) | 150 | if (ret->entries) |
151 | sk_X509_NAME_ENTRY_free(ret->entries); | 151 | sk_X509_NAME_ENTRY_free(ret->entries); |
152 | free(ret); | 152 | free(ret); |
153 | } | 153 | } |
154 | return 0; | 154 | return 0; |
155 | } | 155 | } |
156 | 156 | ||
diff --git a/src/lib/libssl/src/crypto/asn1/x_pkey.c b/src/lib/libssl/src/crypto/asn1/x_pkey.c index c37f207e33..37d2d93968 100644 --- a/src/lib/libssl/src/crypto/asn1/x_pkey.c +++ b/src/lib/libssl/src/crypto/asn1/x_pkey.c | |||
@@ -65,12 +65,12 @@ | |||
65 | 65 | ||
66 | /* need to implement */ | 66 | /* need to implement */ |
67 | int i2d_X509_PKEY(X509_PKEY *a, unsigned char **pp) | 67 | int i2d_X509_PKEY(X509_PKEY *a, unsigned char **pp) |
68 | { | 68 | { |
69 | return(0); | 69 | return(0); |
70 | } | 70 | } |
71 | 71 | ||
72 | X509_PKEY *d2i_X509_PKEY(X509_PKEY **a, const unsigned char **pp, long length) | 72 | X509_PKEY *d2i_X509_PKEY(X509_PKEY **a, const unsigned char **pp, long length) |
73 | { | 73 | { |
74 | int i; | 74 | int i; |
75 | M_ASN1_D2I_vars(a,X509_PKEY *,X509_PKEY_new); | 75 | M_ASN1_D2I_vars(a,X509_PKEY *,X509_PKEY_new); |
76 | 76 | ||
@@ -82,30 +82,30 @@ X509_PKEY *d2i_X509_PKEY(X509_PKEY **a, const unsigned char **pp, long length) | |||
82 | ret->cipher.cipher=EVP_get_cipherbyname( | 82 | ret->cipher.cipher=EVP_get_cipherbyname( |
83 | OBJ_nid2ln(OBJ_obj2nid(ret->enc_algor->algorithm))); | 83 | OBJ_nid2ln(OBJ_obj2nid(ret->enc_algor->algorithm))); |
84 | if (ret->cipher.cipher == NULL) | 84 | if (ret->cipher.cipher == NULL) |
85 | { | 85 | { |
86 | c.error=ASN1_R_UNSUPPORTED_CIPHER; | 86 | c.error=ASN1_R_UNSUPPORTED_CIPHER; |
87 | c.line=__LINE__; | 87 | c.line=__LINE__; |
88 | goto err; | 88 | goto err; |
89 | } | 89 | } |
90 | if (ret->enc_algor->parameter->type == V_ASN1_OCTET_STRING) | 90 | if (ret->enc_algor->parameter->type == V_ASN1_OCTET_STRING) |
91 | { | 91 | { |
92 | i=ret->enc_algor->parameter->value.octet_string->length; | 92 | i=ret->enc_algor->parameter->value.octet_string->length; |
93 | if (i > EVP_MAX_IV_LENGTH) | 93 | if (i > EVP_MAX_IV_LENGTH) |
94 | { | 94 | { |
95 | c.error=ASN1_R_IV_TOO_LARGE; | 95 | c.error=ASN1_R_IV_TOO_LARGE; |
96 | c.line=__LINE__; | 96 | c.line=__LINE__; |
97 | goto err; | 97 | goto err; |
98 | } | 98 | } |
99 | memcpy(ret->cipher.iv, | 99 | memcpy(ret->cipher.iv, |
100 | ret->enc_algor->parameter->value.octet_string->data,i); | 100 | ret->enc_algor->parameter->value.octet_string->data,i); |
101 | } | 101 | } |
102 | else | 102 | else |
103 | memset(ret->cipher.iv,0,EVP_MAX_IV_LENGTH); | 103 | memset(ret->cipher.iv,0,EVP_MAX_IV_LENGTH); |
104 | M_ASN1_D2I_Finish(a,X509_PKEY_free,ASN1_F_D2I_X509_PKEY); | 104 | M_ASN1_D2I_Finish(a,X509_PKEY_free,ASN1_F_D2I_X509_PKEY); |
105 | } | 105 | } |
106 | 106 | ||
107 | X509_PKEY *X509_PKEY_new(void) | 107 | X509_PKEY *X509_PKEY_new(void) |
108 | { | 108 | { |
109 | X509_PKEY *ret=NULL; | 109 | X509_PKEY *ret=NULL; |
110 | ASN1_CTX c; | 110 | ASN1_CTX c; |
111 | 111 | ||
@@ -122,10 +122,10 @@ X509_PKEY *X509_PKEY_new(void) | |||
122 | ret->references=1; | 122 | ret->references=1; |
123 | return(ret); | 123 | return(ret); |
124 | M_ASN1_New_Error(ASN1_F_X509_PKEY_NEW); | 124 | M_ASN1_New_Error(ASN1_F_X509_PKEY_NEW); |
125 | } | 125 | } |
126 | 126 | ||
127 | void X509_PKEY_free(X509_PKEY *x) | 127 | void X509_PKEY_free(X509_PKEY *x) |
128 | { | 128 | { |
129 | int i; | 129 | int i; |
130 | 130 | ||
131 | if (x == NULL) return; | 131 | if (x == NULL) return; |
@@ -138,4 +138,4 @@ void X509_PKEY_free(X509_PKEY *x) | |||
138 | if (x->dec_pkey != NULL)EVP_PKEY_free(x->dec_pkey); | 138 | if (x->dec_pkey != NULL)EVP_PKEY_free(x->dec_pkey); |
139 | if ((x->key_data != NULL) && (x->key_free)) free(x->key_data); | 139 | if ((x->key_data != NULL) && (x->key_free)) free(x->key_data); |
140 | free(x); | 140 | free(x); |
141 | } | 141 | } |
diff --git a/src/lib/libssl/src/crypto/asn1/x_pubkey.c b/src/lib/libssl/src/crypto/asn1/x_pubkey.c index 684f40899f..454d50f24c 100644 --- a/src/lib/libssl/src/crypto/asn1/x_pubkey.c +++ b/src/lib/libssl/src/crypto/asn1/x_pubkey.c | |||
@@ -71,14 +71,14 @@ | |||
71 | /* Minor tweak to operation: free up EVP_PKEY */ | 71 | /* Minor tweak to operation: free up EVP_PKEY */ |
72 | static int pubkey_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, | 72 | static int pubkey_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, |
73 | void *exarg) | 73 | void *exarg) |
74 | { | 74 | { |
75 | if (operation == ASN1_OP_FREE_POST) | 75 | if (operation == ASN1_OP_FREE_POST) |
76 | { | 76 | { |
77 | X509_PUBKEY *pubkey = (X509_PUBKEY *)*pval; | 77 | X509_PUBKEY *pubkey = (X509_PUBKEY *)*pval; |
78 | EVP_PKEY_free(pubkey->pkey); | 78 | EVP_PKEY_free(pubkey->pkey); |
79 | } | ||
80 | return 1; | ||
81 | } | 79 | } |
80 | return 1; | ||
81 | } | ||
82 | 82 | ||
83 | ASN1_SEQUENCE_cb(X509_PUBKEY, pubkey_cb) = { | 83 | ASN1_SEQUENCE_cb(X509_PUBKEY, pubkey_cb) = { |
84 | ASN1_SIMPLE(X509_PUBKEY, algor, X509_ALGOR), | 84 | ASN1_SIMPLE(X509_PUBKEY, algor, X509_ALGOR), |
@@ -88,7 +88,7 @@ ASN1_SEQUENCE_cb(X509_PUBKEY, pubkey_cb) = { | |||
88 | IMPLEMENT_ASN1_FUNCTIONS(X509_PUBKEY) | 88 | IMPLEMENT_ASN1_FUNCTIONS(X509_PUBKEY) |
89 | 89 | ||
90 | int X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey) | 90 | int X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey) |
91 | { | 91 | { |
92 | X509_PUBKEY *pk=NULL; | 92 | X509_PUBKEY *pk=NULL; |
93 | 93 | ||
94 | if (x == NULL) return(0); | 94 | if (x == NULL) return(0); |
@@ -96,28 +96,28 @@ int X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey) | |||
96 | if ((pk=X509_PUBKEY_new()) == NULL) goto error; | 96 | if ((pk=X509_PUBKEY_new()) == NULL) goto error; |
97 | 97 | ||
98 | if (pkey->ameth) | 98 | if (pkey->ameth) |
99 | { | 99 | { |
100 | if (pkey->ameth->pub_encode) | 100 | if (pkey->ameth->pub_encode) |
101 | { | 101 | { |
102 | if (!pkey->ameth->pub_encode(pk, pkey)) | 102 | if (!pkey->ameth->pub_encode(pk, pkey)) |
103 | { | 103 | { |
104 | X509err(X509_F_X509_PUBKEY_SET, | 104 | X509err(X509_F_X509_PUBKEY_SET, |
105 | X509_R_PUBLIC_KEY_ENCODE_ERROR); | 105 | X509_R_PUBLIC_KEY_ENCODE_ERROR); |
106 | goto error; | 106 | goto error; |
107 | } | ||
108 | } | 107 | } |
108 | } | ||
109 | else | 109 | else |
110 | { | 110 | { |
111 | X509err(X509_F_X509_PUBKEY_SET, | 111 | X509err(X509_F_X509_PUBKEY_SET, |
112 | X509_R_METHOD_NOT_SUPPORTED); | 112 | X509_R_METHOD_NOT_SUPPORTED); |
113 | goto error; | 113 | goto error; |
114 | } | ||
115 | } | 114 | } |
115 | } | ||
116 | else | 116 | else |
117 | { | 117 | { |
118 | X509err(X509_F_X509_PUBKEY_SET,X509_R_UNSUPPORTED_ALGORITHM); | 118 | X509err(X509_F_X509_PUBKEY_SET,X509_R_UNSUPPORTED_ALGORITHM); |
119 | goto error; | 119 | goto error; |
120 | } | 120 | } |
121 | 121 | ||
122 | if (*x != NULL) | 122 | if (*x != NULL) |
123 | X509_PUBKEY_free(*x); | 123 | X509_PUBKEY_free(*x); |
@@ -128,62 +128,62 @@ int X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey) | |||
128 | error: | 128 | error: |
129 | if (pk != NULL) X509_PUBKEY_free(pk); | 129 | if (pk != NULL) X509_PUBKEY_free(pk); |
130 | return 0; | 130 | return 0; |
131 | } | 131 | } |
132 | 132 | ||
133 | EVP_PKEY *X509_PUBKEY_get(X509_PUBKEY *key) | 133 | EVP_PKEY *X509_PUBKEY_get(X509_PUBKEY *key) |
134 | { | 134 | { |
135 | EVP_PKEY *ret=NULL; | 135 | EVP_PKEY *ret=NULL; |
136 | 136 | ||
137 | if (key == NULL) goto error; | 137 | if (key == NULL) goto error; |
138 | 138 | ||
139 | if (key->pkey != NULL) | 139 | if (key->pkey != NULL) |
140 | { | 140 | { |
141 | CRYPTO_add(&key->pkey->references, 1, CRYPTO_LOCK_EVP_PKEY); | 141 | CRYPTO_add(&key->pkey->references, 1, CRYPTO_LOCK_EVP_PKEY); |
142 | return key->pkey; | 142 | return key->pkey; |
143 | } | 143 | } |
144 | 144 | ||
145 | if (key->public_key == NULL) goto error; | 145 | if (key->public_key == NULL) goto error; |
146 | 146 | ||
147 | if ((ret = EVP_PKEY_new()) == NULL) | 147 | if ((ret = EVP_PKEY_new()) == NULL) |
148 | { | 148 | { |
149 | X509err(X509_F_X509_PUBKEY_GET, ERR_R_MALLOC_FAILURE); | 149 | X509err(X509_F_X509_PUBKEY_GET, ERR_R_MALLOC_FAILURE); |
150 | goto error; | 150 | goto error; |
151 | } | 151 | } |
152 | 152 | ||
153 | if (!EVP_PKEY_set_type(ret, OBJ_obj2nid(key->algor->algorithm))) | 153 | if (!EVP_PKEY_set_type(ret, OBJ_obj2nid(key->algor->algorithm))) |
154 | { | 154 | { |
155 | X509err(X509_F_X509_PUBKEY_GET,X509_R_UNSUPPORTED_ALGORITHM); | 155 | X509err(X509_F_X509_PUBKEY_GET,X509_R_UNSUPPORTED_ALGORITHM); |
156 | goto error; | 156 | goto error; |
157 | } | 157 | } |
158 | 158 | ||
159 | if (ret->ameth->pub_decode) | 159 | if (ret->ameth->pub_decode) |
160 | { | 160 | { |
161 | if (!ret->ameth->pub_decode(ret, key)) | 161 | if (!ret->ameth->pub_decode(ret, key)) |
162 | { | 162 | { |
163 | X509err(X509_F_X509_PUBKEY_GET, | 163 | X509err(X509_F_X509_PUBKEY_GET, |
164 | X509_R_PUBLIC_KEY_DECODE_ERROR); | 164 | X509_R_PUBLIC_KEY_DECODE_ERROR); |
165 | goto error; | 165 | goto error; |
166 | } | ||
167 | } | 166 | } |
167 | } | ||
168 | else | 168 | else |
169 | { | 169 | { |
170 | X509err(X509_F_X509_PUBKEY_GET, X509_R_METHOD_NOT_SUPPORTED); | 170 | X509err(X509_F_X509_PUBKEY_GET, X509_R_METHOD_NOT_SUPPORTED); |
171 | goto error; | 171 | goto error; |
172 | } | 172 | } |
173 | 173 | ||
174 | /* Check to see if another thread set key->pkey first */ | 174 | /* Check to see if another thread set key->pkey first */ |
175 | CRYPTO_w_lock(CRYPTO_LOCK_EVP_PKEY); | 175 | CRYPTO_w_lock(CRYPTO_LOCK_EVP_PKEY); |
176 | if (key->pkey) | 176 | if (key->pkey) |
177 | { | 177 | { |
178 | CRYPTO_w_unlock(CRYPTO_LOCK_EVP_PKEY); | 178 | CRYPTO_w_unlock(CRYPTO_LOCK_EVP_PKEY); |
179 | EVP_PKEY_free(ret); | 179 | EVP_PKEY_free(ret); |
180 | ret = key->pkey; | 180 | ret = key->pkey; |
181 | } | 181 | } |
182 | else | 182 | else |
183 | { | 183 | { |
184 | key->pkey = ret; | 184 | key->pkey = ret; |
185 | CRYPTO_w_unlock(CRYPTO_LOCK_EVP_PKEY); | 185 | CRYPTO_w_unlock(CRYPTO_LOCK_EVP_PKEY); |
186 | } | 186 | } |
187 | CRYPTO_add(&ret->references, 1, CRYPTO_LOCK_EVP_PKEY); | 187 | CRYPTO_add(&ret->references, 1, CRYPTO_LOCK_EVP_PKEY); |
188 | 188 | ||
189 | return ret; | 189 | return ret; |
@@ -192,7 +192,7 @@ EVP_PKEY *X509_PUBKEY_get(X509_PUBKEY *key) | |||
192 | if (ret != NULL) | 192 | if (ret != NULL) |
193 | EVP_PKEY_free(ret); | 193 | EVP_PKEY_free(ret); |
194 | return(NULL); | 194 | return(NULL); |
195 | } | 195 | } |
196 | 196 | ||
197 | /* Now two pseudo ASN1 routines that take an EVP_PKEY structure | 197 | /* Now two pseudo ASN1 routines that take an EVP_PKEY structure |
198 | * and encode or decode as X509_PUBKEY | 198 | * and encode or decode as X509_PUBKEY |
@@ -200,7 +200,7 @@ EVP_PKEY *X509_PUBKEY_get(X509_PUBKEY *key) | |||
200 | 200 | ||
201 | EVP_PKEY *d2i_PUBKEY(EVP_PKEY **a, const unsigned char **pp, | 201 | EVP_PKEY *d2i_PUBKEY(EVP_PKEY **a, const unsigned char **pp, |
202 | long length) | 202 | long length) |
203 | { | 203 | { |
204 | X509_PUBKEY *xpk; | 204 | X509_PUBKEY *xpk; |
205 | EVP_PKEY *pktmp; | 205 | EVP_PKEY *pktmp; |
206 | xpk = d2i_X509_PUBKEY(NULL, pp, length); | 206 | xpk = d2i_X509_PUBKEY(NULL, pp, length); |
@@ -209,15 +209,15 @@ EVP_PKEY *d2i_PUBKEY(EVP_PKEY **a, const unsigned char **pp, | |||
209 | X509_PUBKEY_free(xpk); | 209 | X509_PUBKEY_free(xpk); |
210 | if(!pktmp) return NULL; | 210 | if(!pktmp) return NULL; |
211 | if(a) | 211 | if(a) |
212 | { | 212 | { |
213 | EVP_PKEY_free(*a); | 213 | EVP_PKEY_free(*a); |
214 | *a = pktmp; | 214 | *a = pktmp; |
215 | } | ||
216 | return pktmp; | ||
217 | } | 215 | } |
216 | return pktmp; | ||
217 | } | ||
218 | 218 | ||
219 | int i2d_PUBKEY(EVP_PKEY *a, unsigned char **pp) | 219 | int i2d_PUBKEY(EVP_PKEY *a, unsigned char **pp) |
220 | { | 220 | { |
221 | X509_PUBKEY *xpk=NULL; | 221 | X509_PUBKEY *xpk=NULL; |
222 | int ret; | 222 | int ret; |
223 | if(!a) return 0; | 223 | if(!a) return 0; |
@@ -225,7 +225,7 @@ int i2d_PUBKEY(EVP_PKEY *a, unsigned char **pp) | |||
225 | ret = i2d_X509_PUBKEY(xpk, pp); | 225 | ret = i2d_X509_PUBKEY(xpk, pp); |
226 | X509_PUBKEY_free(xpk); | 226 | X509_PUBKEY_free(xpk); |
227 | return ret; | 227 | return ret; |
228 | } | 228 | } |
229 | 229 | ||
230 | /* The following are equivalents but which return RSA and DSA | 230 | /* The following are equivalents but which return RSA and DSA |
231 | * keys | 231 | * keys |
@@ -233,7 +233,7 @@ int i2d_PUBKEY(EVP_PKEY *a, unsigned char **pp) | |||
233 | #ifndef OPENSSL_NO_RSA | 233 | #ifndef OPENSSL_NO_RSA |
234 | RSA *d2i_RSA_PUBKEY(RSA **a, const unsigned char **pp, | 234 | RSA *d2i_RSA_PUBKEY(RSA **a, const unsigned char **pp, |
235 | long length) | 235 | long length) |
236 | { | 236 | { |
237 | EVP_PKEY *pkey; | 237 | EVP_PKEY *pkey; |
238 | RSA *key; | 238 | RSA *key; |
239 | const unsigned char *q; | 239 | const unsigned char *q; |
@@ -245,35 +245,35 @@ RSA *d2i_RSA_PUBKEY(RSA **a, const unsigned char **pp, | |||
245 | if (!key) return NULL; | 245 | if (!key) return NULL; |
246 | *pp = q; | 246 | *pp = q; |
247 | if (a) | 247 | if (a) |
248 | { | 248 | { |
249 | RSA_free(*a); | 249 | RSA_free(*a); |
250 | *a = key; | 250 | *a = key; |
251 | } | ||
252 | return key; | ||
253 | } | 251 | } |
252 | return key; | ||
253 | } | ||
254 | 254 | ||
255 | int i2d_RSA_PUBKEY(RSA *a, unsigned char **pp) | 255 | int i2d_RSA_PUBKEY(RSA *a, unsigned char **pp) |
256 | { | 256 | { |
257 | EVP_PKEY *pktmp; | 257 | EVP_PKEY *pktmp; |
258 | int ret; | 258 | int ret; |
259 | if (!a) return 0; | 259 | if (!a) return 0; |
260 | pktmp = EVP_PKEY_new(); | 260 | pktmp = EVP_PKEY_new(); |
261 | if (!pktmp) | 261 | if (!pktmp) |
262 | { | 262 | { |
263 | ASN1err(ASN1_F_I2D_RSA_PUBKEY, ERR_R_MALLOC_FAILURE); | 263 | ASN1err(ASN1_F_I2D_RSA_PUBKEY, ERR_R_MALLOC_FAILURE); |
264 | return 0; | 264 | return 0; |
265 | } | 265 | } |
266 | EVP_PKEY_set1_RSA(pktmp, a); | 266 | EVP_PKEY_set1_RSA(pktmp, a); |
267 | ret = i2d_PUBKEY(pktmp, pp); | 267 | ret = i2d_PUBKEY(pktmp, pp); |
268 | EVP_PKEY_free(pktmp); | 268 | EVP_PKEY_free(pktmp); |
269 | return ret; | 269 | return ret; |
270 | } | 270 | } |
271 | #endif | 271 | #endif |
272 | 272 | ||
273 | #ifndef OPENSSL_NO_DSA | 273 | #ifndef OPENSSL_NO_DSA |
274 | DSA *d2i_DSA_PUBKEY(DSA **a, const unsigned char **pp, | 274 | DSA *d2i_DSA_PUBKEY(DSA **a, const unsigned char **pp, |
275 | long length) | 275 | long length) |
276 | { | 276 | { |
277 | EVP_PKEY *pkey; | 277 | EVP_PKEY *pkey; |
278 | DSA *key; | 278 | DSA *key; |
279 | const unsigned char *q; | 279 | const unsigned char *q; |
@@ -285,34 +285,34 @@ DSA *d2i_DSA_PUBKEY(DSA **a, const unsigned char **pp, | |||
285 | if (!key) return NULL; | 285 | if (!key) return NULL; |
286 | *pp = q; | 286 | *pp = q; |
287 | if (a) | 287 | if (a) |
288 | { | 288 | { |
289 | DSA_free(*a); | 289 | DSA_free(*a); |
290 | *a = key; | 290 | *a = key; |
291 | } | ||
292 | return key; | ||
293 | } | 291 | } |
292 | return key; | ||
293 | } | ||
294 | 294 | ||
295 | int i2d_DSA_PUBKEY(DSA *a, unsigned char **pp) | 295 | int i2d_DSA_PUBKEY(DSA *a, unsigned char **pp) |
296 | { | 296 | { |
297 | EVP_PKEY *pktmp; | 297 | EVP_PKEY *pktmp; |
298 | int ret; | 298 | int ret; |
299 | if(!a) return 0; | 299 | if(!a) return 0; |
300 | pktmp = EVP_PKEY_new(); | 300 | pktmp = EVP_PKEY_new(); |
301 | if(!pktmp) | 301 | if(!pktmp) |
302 | { | 302 | { |
303 | ASN1err(ASN1_F_I2D_DSA_PUBKEY, ERR_R_MALLOC_FAILURE); | 303 | ASN1err(ASN1_F_I2D_DSA_PUBKEY, ERR_R_MALLOC_FAILURE); |
304 | return 0; | 304 | return 0; |
305 | } | 305 | } |
306 | EVP_PKEY_set1_DSA(pktmp, a); | 306 | EVP_PKEY_set1_DSA(pktmp, a); |
307 | ret = i2d_PUBKEY(pktmp, pp); | 307 | ret = i2d_PUBKEY(pktmp, pp); |
308 | EVP_PKEY_free(pktmp); | 308 | EVP_PKEY_free(pktmp); |
309 | return ret; | 309 | return ret; |
310 | } | 310 | } |
311 | #endif | 311 | #endif |
312 | 312 | ||
313 | #ifndef OPENSSL_NO_EC | 313 | #ifndef OPENSSL_NO_EC |
314 | EC_KEY *d2i_EC_PUBKEY(EC_KEY **a, const unsigned char **pp, long length) | 314 | EC_KEY *d2i_EC_PUBKEY(EC_KEY **a, const unsigned char **pp, long length) |
315 | { | 315 | { |
316 | EVP_PKEY *pkey; | 316 | EVP_PKEY *pkey; |
317 | EC_KEY *key; | 317 | EC_KEY *key; |
318 | const unsigned char *q; | 318 | const unsigned char *q; |
@@ -324,38 +324,38 @@ EC_KEY *d2i_EC_PUBKEY(EC_KEY **a, const unsigned char **pp, long length) | |||
324 | if (!key) return(NULL); | 324 | if (!key) return(NULL); |
325 | *pp = q; | 325 | *pp = q; |
326 | if (a) | 326 | if (a) |
327 | { | 327 | { |
328 | EC_KEY_free(*a); | 328 | EC_KEY_free(*a); |
329 | *a = key; | 329 | *a = key; |
330 | } | ||
331 | return(key); | ||
332 | } | 330 | } |
331 | return(key); | ||
332 | } | ||
333 | 333 | ||
334 | int i2d_EC_PUBKEY(EC_KEY *a, unsigned char **pp) | 334 | int i2d_EC_PUBKEY(EC_KEY *a, unsigned char **pp) |
335 | { | 335 | { |
336 | EVP_PKEY *pktmp; | 336 | EVP_PKEY *pktmp; |
337 | int ret; | 337 | int ret; |
338 | if (!a) return(0); | 338 | if (!a) return(0); |
339 | if ((pktmp = EVP_PKEY_new()) == NULL) | 339 | if ((pktmp = EVP_PKEY_new()) == NULL) |
340 | { | 340 | { |
341 | ASN1err(ASN1_F_I2D_EC_PUBKEY, ERR_R_MALLOC_FAILURE); | 341 | ASN1err(ASN1_F_I2D_EC_PUBKEY, ERR_R_MALLOC_FAILURE); |
342 | return(0); | 342 | return(0); |
343 | } | 343 | } |
344 | EVP_PKEY_set1_EC_KEY(pktmp, a); | 344 | EVP_PKEY_set1_EC_KEY(pktmp, a); |
345 | ret = i2d_PUBKEY(pktmp, pp); | 345 | ret = i2d_PUBKEY(pktmp, pp); |
346 | EVP_PKEY_free(pktmp); | 346 | EVP_PKEY_free(pktmp); |
347 | return(ret); | 347 | return(ret); |
348 | } | 348 | } |
349 | #endif | 349 | #endif |
350 | 350 | ||
351 | int X509_PUBKEY_set0_param(X509_PUBKEY *pub, ASN1_OBJECT *aobj, | 351 | int X509_PUBKEY_set0_param(X509_PUBKEY *pub, ASN1_OBJECT *aobj, |
352 | int ptype, void *pval, | 352 | int ptype, void *pval, |
353 | unsigned char *penc, int penclen) | 353 | unsigned char *penc, int penclen) |
354 | { | 354 | { |
355 | if (!X509_ALGOR_set0(pub->algor, aobj, ptype, pval)) | 355 | if (!X509_ALGOR_set0(pub->algor, aobj, ptype, pval)) |
356 | return 0; | 356 | return 0; |
357 | if (penc) | 357 | if (penc) |
358 | { | 358 | { |
359 | if (pub->public_key->data) | 359 | if (pub->public_key->data) |
360 | free(pub->public_key->data); | 360 | free(pub->public_key->data); |
361 | pub->public_key->data = penc; | 361 | pub->public_key->data = penc; |
@@ -363,23 +363,23 @@ int X509_PUBKEY_set0_param(X509_PUBKEY *pub, ASN1_OBJECT *aobj, | |||
363 | /* Set number of unused bits to zero */ | 363 | /* Set number of unused bits to zero */ |
364 | pub->public_key->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); | 364 | pub->public_key->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); |
365 | pub->public_key->flags|=ASN1_STRING_FLAG_BITS_LEFT; | 365 | pub->public_key->flags|=ASN1_STRING_FLAG_BITS_LEFT; |
366 | } | ||
367 | return 1; | ||
368 | } | 366 | } |
367 | return 1; | ||
368 | } | ||
369 | 369 | ||
370 | int X509_PUBKEY_get0_param(ASN1_OBJECT **ppkalg, | 370 | int X509_PUBKEY_get0_param(ASN1_OBJECT **ppkalg, |
371 | const unsigned char **pk, int *ppklen, | 371 | const unsigned char **pk, int *ppklen, |
372 | X509_ALGOR **pa, | 372 | X509_ALGOR **pa, |
373 | X509_PUBKEY *pub) | 373 | X509_PUBKEY *pub) |
374 | { | 374 | { |
375 | if (ppkalg) | 375 | if (ppkalg) |
376 | *ppkalg = pub->algor->algorithm; | 376 | *ppkalg = pub->algor->algorithm; |
377 | if (pk) | 377 | if (pk) |
378 | { | 378 | { |
379 | *pk = pub->public_key->data; | 379 | *pk = pub->public_key->data; |
380 | *ppklen = pub->public_key->length; | 380 | *ppklen = pub->public_key->length; |
381 | } | 381 | } |
382 | if (pa) | 382 | if (pa) |
383 | *pa = pub->algor; | 383 | *pa = pub->algor; |
384 | return 1; | 384 | return 1; |
385 | } | 385 | } |
diff --git a/src/lib/libssl/src/crypto/asn1/x_x509.c b/src/lib/libssl/src/crypto/asn1/x_x509.c index 5734f2b069..ff8bd77024 100644 --- a/src/lib/libssl/src/crypto/asn1/x_x509.c +++ b/src/lib/libssl/src/crypto/asn1/x_x509.c | |||
@@ -143,20 +143,20 @@ IMPLEMENT_ASN1_DUP_FUNCTION(X509) | |||
143 | 143 | ||
144 | int X509_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, | 144 | int X509_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, |
145 | CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func) | 145 | CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func) |
146 | { | 146 | { |
147 | return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_X509, argl, argp, | 147 | return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_X509, argl, argp, |
148 | new_func, dup_func, free_func); | 148 | new_func, dup_func, free_func); |
149 | } | 149 | } |
150 | 150 | ||
151 | int X509_set_ex_data(X509 *r, int idx, void *arg) | 151 | int X509_set_ex_data(X509 *r, int idx, void *arg) |
152 | { | 152 | { |
153 | return(CRYPTO_set_ex_data(&r->ex_data,idx,arg)); | 153 | return(CRYPTO_set_ex_data(&r->ex_data,idx,arg)); |
154 | } | 154 | } |
155 | 155 | ||
156 | void *X509_get_ex_data(X509 *r, int idx) | 156 | void *X509_get_ex_data(X509 *r, int idx) |
157 | { | 157 | { |
158 | return(CRYPTO_get_ex_data(&r->ex_data,idx)); | 158 | return(CRYPTO_get_ex_data(&r->ex_data,idx)); |
159 | } | 159 | } |
160 | 160 | ||
161 | /* X509_AUX ASN1 routines. X509_AUX is the name given to | 161 | /* X509_AUX ASN1 routines. X509_AUX is the name given to |
162 | * a certificate with extra info tagged on the end. Since these | 162 | * a certificate with extra info tagged on the end. Since these |
diff --git a/src/lib/libssl/src/crypto/asn1/x_x509a.c b/src/lib/libssl/src/crypto/asn1/x_x509a.c index b603f82de7..9449f517be 100644 --- a/src/lib/libssl/src/crypto/asn1/x_x509a.c +++ b/src/lib/libssl/src/crypto/asn1/x_x509a.c | |||
@@ -92,13 +92,13 @@ int X509_alias_set1(X509 *x, unsigned char *name, int len) | |||
92 | { | 92 | { |
93 | X509_CERT_AUX *aux; | 93 | X509_CERT_AUX *aux; |
94 | if (!name) | 94 | if (!name) |
95 | { | 95 | { |
96 | if (!x || !x->aux || !x->aux->alias) | 96 | if (!x || !x->aux || !x->aux->alias) |
97 | return 1; | 97 | return 1; |
98 | ASN1_UTF8STRING_free(x->aux->alias); | 98 | ASN1_UTF8STRING_free(x->aux->alias); |
99 | x->aux->alias = NULL; | 99 | x->aux->alias = NULL; |
100 | return 1; | 100 | return 1; |
101 | } | 101 | } |
102 | if(!(aux = aux_get(x))) return 0; | 102 | if(!(aux = aux_get(x))) return 0; |
103 | if(!aux->alias && !(aux->alias = ASN1_UTF8STRING_new())) return 0; | 103 | if(!aux->alias && !(aux->alias = ASN1_UTF8STRING_new())) return 0; |
104 | return ASN1_STRING_set(aux->alias, name, len); | 104 | return ASN1_STRING_set(aux->alias, name, len); |
@@ -108,13 +108,13 @@ int X509_keyid_set1(X509 *x, unsigned char *id, int len) | |||
108 | { | 108 | { |
109 | X509_CERT_AUX *aux; | 109 | X509_CERT_AUX *aux; |
110 | if (!id) | 110 | if (!id) |
111 | { | 111 | { |
112 | if (!x || !x->aux || !x->aux->keyid) | 112 | if (!x || !x->aux || !x->aux->keyid) |
113 | return 1; | 113 | return 1; |
114 | ASN1_OCTET_STRING_free(x->aux->keyid); | 114 | ASN1_OCTET_STRING_free(x->aux->keyid); |
115 | x->aux->keyid = NULL; | 115 | x->aux->keyid = NULL; |
116 | return 1; | 116 | return 1; |
117 | } | 117 | } |
118 | if(!(aux = aux_get(x))) return 0; | 118 | if(!(aux = aux_get(x))) return 0; |
119 | if(!aux->keyid && !(aux->keyid = ASN1_OCTET_STRING_new())) return 0; | 119 | if(!aux->keyid && !(aux->keyid = ASN1_OCTET_STRING_new())) return 0; |
120 | return ASN1_STRING_set(aux->keyid, id, len); | 120 | return ASN1_STRING_set(aux->keyid, id, len); |