// File: /workspace/github_cpp_makefile_star2_O1/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 0x1bf9(%rip), %rsi      # 0xb329
movq %r14, %rdi
callq 0x4510
testq %rax, %rax
je 0x980a
movq %rax, %r12
movq %rax, %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x4610
movq %rax, %r14
movq %r12, %rdi
callq 0x4430
testq %r14, %r14
je 0x9825
leaq 0x1bbc(%rip), %rsi      # 0xb329
movq %r15, %rdi
callq 0x4510
testq %rax, %rax
je 0x9838
movq %rax, %r12
movq %rax, %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x4890
movq %rax, %r15
movq %r12, %rdi
callq 0x4430
testq %r15, %r15
je 0x985f
callq 0x4500
movq %rax, (%rbx)
testq %rax, %rax
je 0x9872
movq %rax, %rdi
movq %r14, %rsi
callq 0x4240
cmpl $0x1, %eax
jne 0x98b1
movq (%rbx), %rdi
movq %r15, %rsi
callq 0x4710
cmpl $0x1, %eax
jne 0x98c3
movq (%rbx), %rdi
movl $0x4, %esi
callq 0x4330
cmpl $0x1, %eax
jne 0x98df
movq %r14, %rdi
callq 0x4210
movq %r15, %rdi
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x41d0
movq 0x67d7(%rip), %rdi      # 0xffe8
leaq 0x1a33(%rip), %rsi      # 0xb24b
callq 0x4420
movq %rax, %rdi
movq %r14, %rsi
jmp 0x9851
movq 0x67bc(%rip), %rdi      # 0xffe8
leaq 0x1a40(%rip), %rsi      # 0xb273
jmp 0x9933
movq 0x67a9(%rip), %rdi      # 0xffe8
leaq 0x1a05(%rip), %rsi      # 0xb24b
callq 0x4420
movq %rax, %rdi
movq %r15, %rsi
callq 0x4420
leaq 0x1a08(%rip), %rsi      # 0xb265
jmp 0x98a9
movq 0x6782(%rip), %rdi      # 0xffe8
leaq 0x1f6d(%rip), %rsi      # 0xb7da
jmp 0x9933
movq 0x676f(%rip), %rdi      # 0xffe8
leaq 0x1f82(%rip), %rsi      # 0xb802
callq 0x4420
movq %rax, %rbx
callq 0x4600
movq %rax, %rdi
xorl %esi, %esi
callq 0x4160
movq %rbx, %rdi
movq %rax, %rsi
callq 0x4420
leaq 0x19c8(%rip), %rsi      # 0xb271
movq %rax, %rdi
jmp 0x9933
movl %eax, %ebp
movq 0x672e(%rip), %rdi      # 0xffe8
leaq 0x1f66(%rip), %rsi      # 0xb827
jmp 0x98d3
movl %eax, %ebp
movq 0x671c(%rip), %rdi      # 0xffe8
leaq 0x1f79(%rip), %rsi      # 0xb84c
callq 0x4420
movq %rax, %rdi
movl %ebp, %esi
jmp 0x98f9
movl %eax, %ebx
movq 0x6700(%rip), %rdi      # 0xffe8
leaq 0x1f81(%rip), %rsi      # 0xb870
callq 0x4420
movq %rax, %rdi
movl %ebx, %esi
callq 0x4790
leaq 0x196c(%rip), %rbx      # 0xb271
movq %rax, %rdi
movq %rbx, %rsi
callq 0x4420
movq %rax, %r14
callq 0x4600
movq %rax, %rdi
xorl %esi, %esi
callq 0x4160
movq %r14, %rdi
movq %rax, %rsi
callq 0x4420
movq %rax, %rdi
movq %rbx, %rsi
callq 0x4420
movl $0x1, %edi
callq 0x4560