MCPcopy Create free account
hub / github.com/Meituan-Dianping/SQLAdvisor / read_file

Function read_file

extra/yassl/src/ssl.cpp:55–146  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

53
54
55int read_file(SSL_CTX* ctx, const char* file, int format, CertType type)
56{
57 if (format != SSL_FILETYPE_ASN1 && format != SSL_FILETYPE_PEM)
58 return SSL_BAD_FILETYPE;
59
60 if (file == NULL || !file[0])
61 return SSL_BAD_FILE;
62
63 FILE* input = fopen(file, "rb");
64 if (!input)
65 return SSL_BAD_FILE;
66
67 if (type == CA) {
68 // may have a bunch of CAs
69 x509* ptr;
70 while ( (ptr = PemToDer(input, Cert)) )
71 ctx->AddCA(ptr);
72
73 if (!feof(input)) {
74 fclose(input);
75 return SSL_BAD_FILE;
76 }
77 }
78 else {
79 x509*& x = (type == Cert) ? ctx->certificate_ : ctx->privateKey_;
80
81 if (format == SSL_FILETYPE_ASN1) {
82 fseek(input, 0, SEEK_END);
83 long sz = ftell(input);
84 rewind(input);
85 x = NEW_YS x509(sz); // takes ownership
86 size_t bytes = fread(x->use_buffer(), sz, 1, input);
87 if (bytes != 1) {
88 fclose(input);
89 return SSL_BAD_FILE;
90 }
91 }
92 else {
93 EncryptedInfo info;
94 x = PemToDer(input, type, &info);
95 if (!x) {
96 fclose(input);
97 return SSL_BAD_FILE;
98 }
99 if (info.set) {
100 // decrypt
101 char password[80];
102 pem_password_cb cb = ctx->GetPasswordCb();
103 if (!cb) {
104 fclose(input);
105 return SSL_BAD_FILE;
106 }
107 int passwordSz = cb(password, sizeof(password), 0,
108 ctx->GetUserData());
109 byte key[AES_256_KEY_SZ]; // max sizes
110 byte iv[AES_IV_SZ];
111
112 // use file's salt for key derivation, but not real iv

Callers 3

Calls 15

PemToDerFunction · 0.85
minFunction · 0.85
EVP_BytesToKeyFunction · 0.85
ysDeleteFunction · 0.85
AddCAMethod · 0.80
use_bufferMethod · 0.80
GetPasswordCbMethod · 0.80
GetUserDataMethod · 0.80
x509Class · 0.50
AESClass · 0.50
get_bufferMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected