1 === modified file 'extra/yassl/taocrypt/include/asn.hpp' |
|
2 --- extra/yassl/taocrypt/include/asn.hpp 2007-01-29 15:54:40 +0000 |
|
3 +++ extra/yassl/taocrypt/include/asn.hpp.org 2010-01-13 05:20:45 +0000 |
|
4 @@ -305,6 +305,7 @@ private: |
|
5 bool ValidateSignature(SignerList*); |
|
6 bool ConfirmSignature(Source&); |
|
7 void GetKey(); |
|
8 + char* AddTag(char*, const char*, const char*, word32, word32); |
|
9 void GetName(NameType); |
|
10 void GetValidity(); |
|
11 void GetDate(DateType); |
|
12 |
|
13 === modified file 'extra/yassl/taocrypt/src/asn.cpp' |
|
14 --- extra/yassl/taocrypt/src/asn.cpp 2009-06-29 13:17:01 +0000 |
|
15 +++ extra/yassl/taocrypt/src/asn.cpp.org 2010-01-13 05:20:45 +0000 |
|
16 @@ -652,6 +652,23 @@ word32 CertDecoder::GetDigest() |
|
17 } |
|
18 |
|
19 |
|
20 +char *CertDecoder::AddTag(char *ptr, const char *buf_end, |
|
21 + const char *tag_name, word32 tag_name_length, |
|
22 + word32 tag_value_length) |
|
23 +{ |
|
24 + if (ptr + tag_name_length + tag_value_length > buf_end) |
|
25 + return 0; |
|
26 + |
|
27 + memcpy(ptr, tag_name, tag_name_length); |
|
28 + ptr+= tag_name_length; |
|
29 + |
|
30 + memcpy(ptr, source_.get_current(), tag_value_length); |
|
31 + ptr+= tag_value_length; |
|
32 + |
|
33 + return ptr; |
|
34 +} |
|
35 + |
|
36 + |
|
37 // process NAME, either issuer or subject |
|
38 void CertDecoder::GetName(NameType nt) |
|
39 { |
|
40 @@ -659,11 +676,21 @@ void CertDecoder::GetName(NameType nt) |
|
41 |
|
42 SHA sha; |
|
43 word32 length = GetSequence(); // length of all distinguished names |
|
44 - assert (length < ASN_NAME_MAX); |
|
45 + |
|
46 + if (length >= ASN_NAME_MAX) |
|
47 + goto err; |
|
48 length += source_.get_index(); |
|
49 |
|
50 - char* ptr = (nt == ISSUER) ? issuer_ : subject_; |
|
51 - word32 idx = 0; |
|
52 + char *ptr, *buf_end; |
|
53 + |
|
54 + if (nt == ISSUER) { |
|
55 + ptr= issuer_; |
|
56 + buf_end= ptr + sizeof(issuer_) - 1; // 1 byte for trailing 0 |
|
57 + } |
|
58 + else { |
|
59 + ptr= subject_; |
|
60 + buf_end= ptr + sizeof(subject_) - 1; // 1 byte for trailing 0 |
|
61 + } |
|
62 |
|
63 while (source_.get_index() < length) { |
|
64 GetSet(); |
|
65 @@ -685,47 +712,36 @@ void CertDecoder::GetName(NameType nt) |
|
66 byte id = source_.next(); |
|
67 b = source_.next(); // strType |
|
68 word32 strLen = GetLength(source_); |
|
69 - bool copy = false; |
|
70 |
|
71 - if (id == COMMON_NAME) { |
|
72 - memcpy(&ptr[idx], "/CN=", 4); |
|
73 - idx += 4; |
|
74 - copy = true; |
|
75 - } |
|
76 - else if (id == SUR_NAME) { |
|
77 - memcpy(&ptr[idx], "/SN=", 4); |
|
78 - idx += 4; |
|
79 - copy = true; |
|
80 - } |
|
81 - else if (id == COUNTRY_NAME) { |
|
82 - memcpy(&ptr[idx], "/C=", 3); |
|
83 - idx += 3; |
|
84 - copy = true; |
|
85 - } |
|
86 - else if (id == LOCALITY_NAME) { |
|
87 - memcpy(&ptr[idx], "/L=", 3); |
|
88 - idx += 3; |
|
89 - copy = true; |
|
90 - } |
|
91 - else if (id == STATE_NAME) { |
|
92 - memcpy(&ptr[idx], "/ST=", 4); |
|
93 - idx += 4; |
|
94 - copy = true; |
|
95 - } |
|
96 - else if (id == ORG_NAME) { |
|
97 - memcpy(&ptr[idx], "/O=", 3); |
|
98 - idx += 3; |
|
99 - copy = true; |
|
100 - } |
|
101 - else if (id == ORGUNIT_NAME) { |
|
102 - memcpy(&ptr[idx], "/OU=", 4); |
|
103 - idx += 4; |
|
104 - copy = true; |
|
105 - } |
|
106 - |
|
107 - if (copy) { |
|
108 - memcpy(&ptr[idx], source_.get_current(), strLen); |
|
109 - idx += strLen; |
|
110 + switch (id) { |
|
111 + case COMMON_NAME: |
|
112 + if (!(ptr= AddTag(ptr, buf_end, "/CN=", 4, strLen))) |
|
113 + goto err; |
|
114 + break; |
|
115 + case SUR_NAME: |
|
116 + if (!(ptr= AddTag(ptr, buf_end, "/SN=", 4, strLen))) |
|
117 + goto err; |
|
118 + break; |
|
119 + case COUNTRY_NAME: |
|
120 + if (!(ptr= AddTag(ptr, buf_end, "/C=", 3, strLen))) |
|
121 + goto err; |
|
122 + break; |
|
123 + case LOCALITY_NAME: |
|
124 + if (!(ptr= AddTag(ptr, buf_end, "/L=", 3, strLen))) |
|
125 + goto err; |
|
126 + break; |
|
127 + case STATE_NAME: |
|
128 + if (!(ptr= AddTag(ptr, buf_end, "/ST=", 4, strLen))) |
|
129 + goto err; |
|
130 + break; |
|
131 + case ORG_NAME: |
|
132 + if (!(ptr= AddTag(ptr, buf_end, "/O=", 3, strLen))) |
|
133 + goto err; |
|
134 + break; |
|
135 + case ORGUNIT_NAME: |
|
136 + if (!(ptr= AddTag(ptr, buf_end, "/OU=", 4, strLen))) |
|
137 + goto err; |
|
138 + break; |
|
139 } |
|
140 |
|
141 sha.Update(source_.get_current(), strLen); |
|
142 @@ -739,23 +755,20 @@ void CertDecoder::GetName(NameType nt) |
|
143 source_.advance(oidSz + 1); |
|
144 word32 length = GetLength(source_); |
|
145 |
|
146 - if (email) { |
|
147 - memcpy(&ptr[idx], "/emailAddress=", 14); |
|
148 - idx += 14; |
|
149 - |
|
150 - memcpy(&ptr[idx], source_.get_current(), length); |
|
151 - idx += length; |
|
152 - } |
|
153 + if (email && !(ptr= AddTag(ptr, buf_end, "/emailAddress=", 14, length))) |
|
154 + goto err; |
|
155 |
|
156 source_.advance(length); |
|
157 } |
|
158 } |
|
159 - ptr[idx++] = 0; |
|
160 + *ptr= 0; |
|
161 |
|
162 - if (nt == ISSUER) |
|
163 - sha.Final(issuerHash_); |
|
164 - else |
|
165 - sha.Final(subjectHash_); |
|
166 + sha.Final(nt == ISSUER ? issuerHash_ : subjectHash_); |
|
167 + |
|
168 + return; |
|
169 + |
|
170 +err: |
|
171 + source_.SetError(CONTENT_E); |
|
172 } |
|
173 |
|