I. Introduction
Currently, most SSL-related information on the Internet is developed based on VC, and Delphi has few SSL development resources.
This article describes the development process of SSL Based on OpenSSL. OpenSSL features are rich. For details, visit her official website. Unfortunately, there is no Chinese explanation.
OpenSSL: http://www.openssl.org/
I. 1. What is the SSL protocol?
SSL stands for the Secure Sockets Layer. It is a standard that supports secure communication over the Internet and integrates data cryptography into the Protocol. Data is encrypted before it leaves your computer and decrypted only after it reaches its intended destination. Certificates and cryptographic algorithms support all these operations. With OpenSSL, you will have the opportunity to understand them.
Theoretically, if the encrypted data is intercepted or eavesdropped before it reaches the target, the data cannot be cracked. However, since the computer changes faster than a year ago and the password translation method has developed, the possibility of cracking the encryption protocol used in SSL is also increasing.
SSL and secure connections can be used for any type of protocol on the internet, whether HTTP, POP3, or FTP. You can also use SSL to protect Telnet sessions. Although SSL can be used to protect any connection, SSL is not required for each type of connection. If the connection transmits sensitive information, use SSL.
I. 2. What is OpenSSL?
OpenSSL is not just SSL. It can implement message digest, file encryption and decryption, digital certificates, digital signatures and random numbers. There are a lot of content about the OpenSSL library, which is far from an article.
OpenSSL is not just an API, but also a command line tool. The command line tool can do the same work as the API, and further test the SSL server and client. It also gives developers an understanding of OpenSSL capabilities.
Ii. Description of CA concepts
Ca is the certificate issuing authority and is the core of PKI. Ca is the authority responsible for issuing certificates, certification certificates, and managing issued certificates. It requires policies and specific steps to verify and identify user identities, and sign user certificates to ensure the ownership of the identity and public key of the certificate holder.
CA also has a certificate (containing the Public Key) and a private key. Public users on the Internet trust the CA by verifying the signature of the CA. Anyone can obtain the CA certificate (including the public key) to verify the certificate issued by the CA.
If you want to obtain a certificate of your own, you must first apply to the CA. After the CA determines the applicant's identity, it will assign a public key to the applicant, and the CA will bind the public key with the applicant's identity information and sign it, and then form a certificate to the applicant.
If a user wants to identify the authenticity of another certificate, he will use the CA Public Key to verify the signature on that certificate. Once the verification passes, the certificate will be considered valid.
Ii. 1. Certificate
The certificate is actually issued by the Certificate Authority (CA) to authenticate the user's public key.
The certificate content includes: information of the e-Visa authority, public key user information, public key, signature and validity period of the authority, etc. At present, the Certificate Format and verification method are generally followed by X. 509 international standards.
How can we implement signatures in electronic documents? We can use digital signatures. The RSA public key system can sign digital information as follows:
Information senders use their private keys to perform RSA algorithm operations on the feature data (or digital fingerprints) extracted from the reported text, to ensure that the sender is not allowed to deny the information that has been sent (that is, non-repudiation), and to ensure that the information packets are not tampered with (that is, integrity) during transmission ). After receiving the message, the message receiver can use the sender's public key to verify the digital signature.
Digital fingerprints that play an important role in digital signatures are generated using a special hash function. The special requirements for these hash functions are:
1. The received input message data has no length limit;
2. Generate a fixed-length Digest (digital fingerprint) Output for any input message data;
3. The Digest can be easily calculated from the message;
4. It is difficult to generate a message for the specified abstract, and the specified abstract can be calculated from the message;
5. It is difficult to generate two different packets with the same digest.
Verification:
After receiving the information, the recipient verifies your signature using the following steps:
1. Use your private key to convert the information into plaintext;
2. Use the sender's public key to obtain the original abstract from the digital signature section;
3. The recipient performs a hash operation on the source information you sent, and generates a summary;
4. The recipient compares the two summaries. If the two summaries are the same, the identity of the Information signer can be proved.
If the two summaries do not match, why?
The private key that may be used to sign the digest is not the private key of the signatory. This indicates that the signatory of the information is untrusted. The information that may be received is not the information sent by the signatory at all, information has been damaged or tampered with during transmission.
Ii. 2. Digital Certificate
Digital certificates provide electronic authentication for secure communication between the two parties. Digital Certificates are used for identity identification and electronic information encryption on the Internet, Intranet, or external networks. The digital certificate contains the identification information of the owner of the key pair (Public Key and private key). The authenticity of the authentication information is used to authenticate the identity of the certificate holder.
Ii. 3. What can I do with a digital certificate?
The digital certificate attaches the user information and the CA signature to the user's public key. The Public Key is part of the key pair, and the other is the private key. Everyone can use the public key. The private key is only known to you. Information encrypted by the Public Key can only be decrypted by the corresponding private key. To ensure that only one individual can read his/her own mail, the sender must encrypt the mail with the recipient's public key. The recipient can decrypt the mail with his/her own private key. Similarly, to verify the sender's identity, the sender must sign the letter with his/her own private key. The recipient can use the sender's public key to verify the signature to confirm the sender's identity.
In online transactions, you can use a digital certificate to verify the identity of the peer. Using digital certificates to encrypt information ensures that only the recipient can decrypt and read the original text, and the confidentiality and integrity of the information during transmission. With digital certificate online security, the security of email, online transactions, and credit card shopping can be ensured.
Ii. 4. Authentication, digital certificates, and PKI solutions
L confidentiality-only the recipient can read the information.
L Authentication-confirm the identity of the Information sender.
L integrity-information will not be tampered with during transmission.
L Non-Repudiation-the sender cannot deny the sent information.
3. Set up SSL Workflow
(Set up OpenSSL)
(How to obtain the root certificate)
Iv. Development IV. 1. Compile OpenSSL IV. 1.1 and set up preparations
1. OpenSSL source code. You can download the latest code from the official website.
2. Compile the dynamic library using the standard C compiler (VC can be used here.
3. perl5 compiling environment. OpenSSL compiling requires a Perl environment. Some on the official website.
Iv. 1.2. Compile the dynamic library
OpenSSL source code library path: C: "opensslsource
1. Enter the VC command line compiling environment
2. Go to the OpenSSL source code Directory: cd c: "opensslsource
3. Execute configure: Perl configure VC-WIN32 -- prefix = C:/OpenSSL
4. Create a MAKEFILE file: MS "do_ms
5. Compile the dynamic library: nmake-F ms "NTDLL. Mak
6. Test the dynamic library: nmake-F ms "NTDLL. Mak Test
7. Install the dynamic library: nmake-F ms "NTDLL. Mak install
8. Clear the zero-time file for later Compilation: nmake-F ms "NTDLL. Mak clean
Note: To generate a VC static library, you only need to compile the make file of MS "nt. Mak.
Iv. 2. Generate a certificate
Due to the wide variety of OpenSSL commands, we will not detail them here. Specific can see: BBS shuimu Tsinghua station (frinov1020: 24: 102000) fordesign@21cn.com translation content. The documents have been organized into a directory.
Iv. 2.1 generate the private key (key file) of the server)
OpenSSL genrsa-des3-out server. Key 1024
The system will prompt you to enter the password during the operation. This password is used to encrypt the key file (the des3 parameter refers to the encryption algorithm. Of course, you can also choose other algorithms that you think are safe .), In the future, whenever you need to read this file (through commands or APIs provided by OpenSSL), you need to enter a password. If it is inconvenient, you can also remove the password, but you must take other protection measures!
Command to remove the key file Password:
OpenSSL RSA-in server. Key-out server. Key
Iv. 2.2 generate a certificate request
OpenSSL req-New-key server. Key-out server. CSR-config OpenSSL. CNF
Generate a Certificate Signing Request (CSR). The generated CSR file is handed over to the CA for signature and the certificate is generated by the server. There will be a prompt on the screen. Follow the instructions to enter the required personal information step by step.
Iv. 2.3 generate the customer key and CSR File
OpenSSL genrsa-des3-out client. Key 1024
OpenSSL req-New-key client. Key-out client. CSR-config OpenSSL. CNF
Iv. 2.4. CA certificate visa
The CSR file must have a ca signature to form a certificate. It can be sent to Verisign and other places for verification. The service fee is required for Ca verification. You can generate the service fee for testing.
OpenSSL req-New-X509-keyout ca. Key-out ca. CRT-config OpenSSL. CNF
Iv. 2.5 generate visa documents
Use the generated CA certificate as the server. CSR, client. CSR file signature:
OpenSSL ca-in server. CSR-out server. CRT-Cert CA. CRT-Keyfile ca. Key-config OpenSSL. CNF
OpenSSL ca-in client. CSR-out client. CRT-Cert CA. CRT-Keyfile ca. Key-config OpenSSL. CNF
Iv. 2.6. Merge PEM files
The PEM file is an X.509 Pam encoded (base64) file, which is a text file. You can use the X.509 command for merging, or copy and paste it directly.
The Server File and client file generated above are merged into two PEM files.
The files used by server include ca. CRT, server. CRT, and server. Key.
Client files include ca. CRT, client. CRT, and client. Key.
Merge the. CRT file and. Key file into the same. pem file.
Iv. 3. Delphi access
We can directly load and use the dynamic OpenSSL library generated above. In addition, the Indy component encapsulates the OpenSSL function module and can reference the uidsslopensslheaders. Pas unit text for development.
Loading dynamic libraries directly is cumbersome, so we can apply the unit development provided by Indy directly. The version of the Indy unit file is relatively old, so an error occurs when loading the new DLL. Find an Indy unit file that supports the latest dynamic library 0.9.7i OpenSSL on the Internet.
For specific application development, see the code in source.
Iv. 3.1 server call process IV. 3.2. customer segment call Process