// File: /workspace/github_cpp_makefile_star2_O2/luigix25[P]SSLP/library/CertificateManager.cpp
// Function: CertificateManager::CertificateManager(char const*, char const*)
CertificateManager::CertificateManager(const char *ca_cert_path, const char *ca_crl_path){

	int ret;
	
	//Load ca_cert
	FILE* cacert_file = fopen(ca_cert_path, "r");
	if(!cacert_file){ cerr << "Error: cannot open file '" << ca_cert_path << "' (missing?)\n"; exit(1); }
	X509* cacert = PEM_read_X509(cacert_file, NULL, NULL, NULL);
	fclose(cacert_file);
	if(!cacert){ cerr << "Error: PEM_read_X509 returned NULL\n"; exit(1); }

	//Load ca_crl
	FILE* crl_file = fopen(ca_crl_path, "r");
	if(!crl_file){ cerr << "Error: cannot open file '" << ca_crl_path << "' (missing?)\n"; exit(1); }
	X509_CRL* crl = PEM_read_X509_CRL(crl_file, NULL, NULL, NULL);
	fclose(crl_file);
	if(!crl){ cerr << "Error: PEM_read_X509_CRL returned NULL\n"; exit(1); }
	
	//Creating the store
	this->store = X509_STORE_new();
	if(!this->store) { cerr << "Error: X509_STORE_new returned NULL\n" << ERR_error_string(ERR_get_error(), NULL) << "\n"; exit(1); }
	ret = X509_STORE_add_cert(this->store, cacert);
	if(ret != 1) { cerr << "Error: X509_STORE_add_cert returned " << ret << "\n" << ERR_error_string(ERR_get_error(), NULL) << "\n"; exit(1); }
	ret = X509_STORE_add_crl(this->store, crl);
	if(ret != 1) { cerr << "Error: X509_STORE_add_crl returned " << ret << "\n" << ERR_error_string(ERR_get_error(), NULL) << "\n"; exit(1); }
	ret = X509_STORE_set_flags(this->store, X509_V_FLAG_CRL_CHECK);
	if(ret != 1) { cerr << "Error: X509_STORE_set_flags returned " << ret << "\n" << ERR_error_string(ERR_get_error(), NULL) << "\n"; exit(1); }

	X509_free(cacert);
	X509_CRL_free(crl);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rdx, %r15
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x1aa1(%rip), %rsi      # 0xa329
movq %r14, %rdi
callq 0x44f0
testq %rax, %rax
je 0x8960
movq %rax, %r12
movq %rax, %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x4600
movq %rax, %r14
movq %r12, %rdi
callq 0x4410
testq %r14, %r14
je 0x897b
leaq 0x1a64(%rip), %rsi      # 0xa329
movq %r15, %rdi
callq 0x44f0
testq %rax, %rax
je 0x898e
movq %rax, %r12
movq %rax, %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x4870
movq %rax, %r15
movq %r12, %rdi
callq 0x4410
testq %r15, %r15
je 0x89b5
callq 0x44d0
movq %rax, (%rbx)
testq %rax, %rax
je 0x89c8
movq %rax, %rdi
movq %r14, %rsi
callq 0x4230
cmpl $0x1, %eax
jne 0x8a07
movq (%rbx), %rdi
movq %r15, %rsi
callq 0x4700
cmpl $0x1, %eax
jne 0x8a19
movq (%rbx), %rdi
pushq $0x4
popq %rsi
callq 0x4320
cmpl $0x1, %eax
jne 0x8a35
movq %r14, %rdi
callq 0x4200
movq %r15, %rdi
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x41c0
movq 0x6689(%rip), %rdi      # 0xeff0
leaq 0x18dd(%rip), %rsi      # 0xa24b
callq 0x4400
movq %rax, %rdi
movq %r14, %rsi
jmp 0x89a7
movq 0x666e(%rip), %rdi      # 0xeff0
leaq 0x18ea(%rip), %rsi      # 0xa273
jmp 0x8a89
movq 0x665b(%rip), %rdi      # 0xeff0
leaq 0x18af(%rip), %rsi      # 0xa24b
callq 0x4400
movq %rax, %rdi
movq %r15, %rsi
callq 0x4400
leaq 0x18b2(%rip), %rsi      # 0xa265
jmp 0x89ff
movq 0x6634(%rip), %rdi      # 0xeff0
leaq 0x1e27(%rip), %rsi      # 0xa7ea
jmp 0x8a89
movq 0x6621(%rip), %rdi      # 0xeff0
leaq 0x1e3c(%rip), %rsi      # 0xa812
callq 0x4400
movq %rax, %rbx
callq 0x45f0
movq %rax, %rdi
xorl %esi, %esi
callq 0x4140
movq %rbx, %rdi
movq %rax, %rsi
callq 0x4400
leaq 0x1872(%rip), %rsi      # 0xa271
movq %rax, %rdi
jmp 0x8a89
movl %eax, %ebp
movq 0x65e0(%rip), %rdi      # 0xeff0
leaq 0x1e20(%rip), %rsi      # 0xa837
jmp 0x8a29
movl %eax, %ebp
movq 0x65ce(%rip), %rdi      # 0xeff0
leaq 0x1e33(%rip), %rsi      # 0xa85c
callq 0x4400
movq %rax, %rdi
movl %ebp, %esi
jmp 0x8a4f
movl %eax, %ebx
movq 0x65b2(%rip), %rdi      # 0xeff0
leaq 0x1e3b(%rip), %rsi      # 0xa880
callq 0x4400
movq %rax, %rdi
movl %ebx, %esi
callq 0x4770
leaq 0x1816(%rip), %rbx      # 0xa271
movq %rax, %rdi
movq %rbx, %rsi
callq 0x4400
movq %rax, %r14
callq 0x45f0
movq %rax, %rdi
xorl %esi, %esi
callq 0x4140
movq %r14, %rdi
movq %rax, %rsi
callq 0x4400
movq %rax, %rdi
movq %rbx, %rsi
callq 0x4400
pushq $0x1
popq %rdi
callq 0x4540