// File: 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
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rdi
leaq 0x1e42(%rip), %rsi      # 0xe329
callq 0x45f0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0xc52f
movq 0x6aea(%rip), %rdi      # 0x12fe8
leaq 0x1d46(%rip), %rsi      # 0xe24b
callq 0x44a0
movq %rax, %rdi
movq -0x10(%rbp), %rsi
callq 0x44a0
movq %rax, %rdi
leaq 0x1d45(%rip), %rsi      # 0xe265
callq 0x44a0
movl $0x1, %edi
callq 0x4640
movq -0x28(%rbp), %rdi
xorl %eax, %eax
movl %eax, %ecx
movq %rcx, %rsi
movq %rcx, %rdx
callq 0x4730
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rdi
callq 0x44b0
cmpq $0x0, -0x30(%rbp)
jne 0xc573
movq 0x6a8b(%rip), %rdi      # 0x12fe8
leaq 0x1d0f(%rip), %rsi      # 0xe273
callq 0x44a0
movl $0x1, %edi
callq 0x4640
movq -0x18(%rbp), %rdi
leaq 0x1dab(%rip), %rsi      # 0xe329
callq 0x45f0
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0xc5c6
movq 0x6a53(%rip), %rdi      # 0x12fe8
leaq 0x1caf(%rip), %rsi      # 0xe24b
callq 0x44a0
movq %rax, %rdi
movq -0x18(%rbp), %rsi
callq 0x44a0
movq %rax, %rdi
leaq 0x1cae(%rip), %rsi      # 0xe265
callq 0x44a0
movl $0x1, %edi
callq 0x4640
movq -0x38(%rbp), %rdi
xorl %eax, %eax
movl %eax, %ecx
movq %rcx, %rsi
movq %rcx, %rdx
callq 0x49d0
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rdi
callq 0x44b0
cmpq $0x0, -0x40(%rbp)
jne 0xc60a
movq 0x69f4(%rip), %rdi      # 0x12fe8
leaq 0x21df(%rip), %rsi      # 0xe7da
callq 0x44a0
movl $0x1, %edi
callq 0x4640
callq 0x45d0
movq %rax, %rcx
movq -0x48(%rbp), %rax
movq %rcx, (%rax)
cmpq $0x0, (%rax)
jne 0xc66c
movq 0x69c2(%rip), %rdi      # 0x12fe8
leaq 0x21d5(%rip), %rsi      # 0xe802
callq 0x44a0
movq %rax, -0x50(%rbp)
callq 0x4710
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x4180
movq -0x50(%rbp), %rdi
movq %rax, %rsi
callq 0x44a0
movq %rax, %rdi
leaq 0x1c14(%rip), %rsi      # 0xe271
callq 0x44a0
movl $0x1, %edi
callq 0x4640
movq -0x48(%rbp), %rax
movq (%rax), %rdi
movq -0x30(%rbp), %rsi
callq 0x4290
movl %eax, -0x1c(%rbp)
cmpl $0x1, -0x1c(%rbp)
je 0xc6ec
movq 0x695c(%rip), %rdi      # 0x12fe8
leaq 0x2194(%rip), %rsi      # 0xe827
callq 0x44a0
movq %rax, %rdi
movl -0x1c(%rbp), %esi
callq 0x48d0
movq %rax, %rdi
leaq 0x1bc4(%rip), %rsi      # 0xe271
callq 0x44a0
movq %rax, -0x58(%rbp)
callq 0x4710
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x4180
movq -0x58(%rbp), %rdi
movq %rax, %rsi
callq 0x44a0
movq %rax, %rdi
leaq 0x1b94(%rip), %rsi      # 0xe271
callq 0x44a0
movl $0x1, %edi
callq 0x4640
movq -0x48(%rbp), %rax
movq (%rax), %rdi
movq -0x40(%rbp), %rsi
callq 0x4840
movl %eax, -0x1c(%rbp)
cmpl $0x1, -0x1c(%rbp)
je 0xc76c
movq 0x68dc(%rip), %rdi      # 0x12fe8
leaq 0x2139(%rip), %rsi      # 0xe84c
callq 0x44a0
movq %rax, %rdi
movl -0x1c(%rbp), %esi
callq 0x48d0
movq %rax, %rdi
leaq 0x1b44(%rip), %rsi      # 0xe271
callq 0x44a0
movq %rax, -0x60(%rbp)
callq 0x4710
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x4180
movq -0x60(%rbp), %rdi
movq %rax, %rsi
callq 0x44a0
movq %rax, %rdi
leaq 0x1b14(%rip), %rsi      # 0xe271
callq 0x44a0
movl $0x1, %edi
callq 0x4640
movq -0x48(%rbp), %rax
movq (%rax), %rdi
movl $0x4, %esi
callq 0x4390
movl %eax, -0x1c(%rbp)
cmpl $0x1, -0x1c(%rbp)
je 0xc7ed
movq 0x685b(%rip), %rdi      # 0x12fe8
leaq 0x20dc(%rip), %rsi      # 0xe870
callq 0x44a0
movq %rax, %rdi
movl -0x1c(%rbp), %esi
callq 0x48d0
movq %rax, %rdi
leaq 0x1ac3(%rip), %rsi      # 0xe271
callq 0x44a0
movq %rax, -0x68(%rbp)
callq 0x4710
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x4180
movq -0x68(%rbp), %rdi
movq %rax, %rsi
callq 0x44a0
movq %rax, %rdi
leaq 0x1a93(%rip), %rsi      # 0xe271
callq 0x44a0
movl $0x1, %edi
callq 0x4640
movq -0x30(%rbp), %rdi
callq 0x4250
movq -0x40(%rbp), %rdi
callq 0x4220
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)