| 6 | // |
| 7 | // https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 |
| 15 | #include <openssl/pem.h> |
| 16 |
| 17 | #include <stdio.h> |
| 18 |
| 19 | #include <openssl/err.h> |
| 20 | #include <openssl/evp.h> |
| 21 | #include <openssl/mem.h> |
| 22 | #include <openssl/obj.h> |
| 23 | #include <openssl/rand.h> |
| 24 | #include <openssl/x509.h> |
| 25 |
| 26 | // Handle 'other' PEMs: not private keys |
| 27 |
| 28 | void *PEM_ASN1_read_bio(d2i_of_void *d2i, const char *name, BIO *bp, void **x, |
| 29 | pem_password_cb *cb, void *u) { |
| 30 | const unsigned char *p = NULL; |
| 31 | unsigned char *data = NULL; |
| 32 | long len; |
| 33 | char *ret = NULL; |
| 34 |
| 35 | if (!PEM_bytes_read_bio(&data, &len, NULL, name, bp, cb, u)) { |
| 36 | return NULL; |
| 37 | } |
| 38 | p = data; |
| 39 | ret = reinterpret_cast<char *>(d2i(x, &p, len)); |
| 40 | if (ret == NULL) { |
| 41 | OPENSSL_PUT_ERROR(PEM, ERR_R_ASN1_LIB); |
| 42 | } |
| 43 | OPENSSL_free(data); |
| 44 | return ret; |
| 45 | } |
| 46 |