Note: Other examples of using SSL with Caché DBMS are mirroring, Telnet, TCP / IP (sockets), web services, Caché Studio, etc. - You can find in the documentation or technical support .First, let's generate the certificates themselves: the root (CA: Certificate Authority), server and client.
Note: Having an eToken is desirable but not necessary.
openssl genrsa -out cakey.pem -rand randfile 4096 openssl genrsa -out serverkey.pem -rand randfile 2048 openssl genrsa -out clientkey.pem -rand randfile 2048
openssl req -new -key cakey.pem -config cfgCA.txt -out cacsr.pem openssl req -new -key serverkey.pem -config cfgServer.txt -out servercsr.pem openssl req -new -key clientkey.pem -config cfgClient.txt -out clientcsr.pem
openssl x509 -req -signkey cakey.pem -in cacsr.pem -extfile cfgCA.txt -extensions v3_req -out cacrt.pem -days 365 openssl ca -config ca.config -extensions v3_server -in servercsr.pem -out servercrt.pem -batch openssl ca -config ca.config -extensions v3_client -in clientcsr.pem -out clientcrt.pem -batch
openssl x509 -inform PEM -in cacrt.pem -outform DER -out ca.cer openssl x509 -inform PEM -in servercrt.pem -outform DER -out server.cer openssl x509 -inform PEM -in clientcrt.pem -outform DER -out client.cer openssl pkcs12 -export -in cacrt.pem -inkey cakey.pem -out ca.pfx -name "CA certificate CACHE" openssl pkcs12 -export -in servercrt.pem -inkey serverkey.pem -out server.pfx -name "Server certificate CACHE" openssl pkcs12 -export -in clientcrt.pem -inkey clientkey.pem -out client.pfx -name "Client certificate CACHE"
rem openssl ca -config ca.config -revoke clientcrt.pem openssl ca -config ca.config -gencrl -out crl.pem openssl crl -outform DER -in crl.pem -out crl.crl -CAfile cacrt.pem copy crl.crl C:\Inetpub\wwwroot\crl.crl
openssl x509 -in cacrt.pem -noout -text >ca.log openssl x509 -in servercrt.pem -noout -text >server.log openssl x509 -in clientcrt.pem -noout -text >client.log openssl crl -in crl.pem -text -noout
openssl verify -CAfile cacrt.pem servercrt.pem clientcrt.pem
[ca] default_ca=CA_CLIENT [CA_CLIENT] dir=./db certs = $dir/certs new_certs_dir = $dir/newcerts database = $dir/index.txt serial = $dir/serial certificate = ./cacrt.pem private_key = ./cakey.pem default_days = 365 default_crl_hours = 4 default_md = sha1 policy = policy_anything # [policy_anything] countryName = optional stateOrProvinceName = optional localityName = optional organizationName = optional organizationalUnitName = optional commonName = supplied emailAddress = optional serialNumber = optional [v3_server] basicConstraints = critical,CA:false nsComment = "Server certificate CACHE" nsCertType = server keyUsage = critical,digitalSignature, nonRepudiation, keyEncipherment, keyAgreement crlDistributionPoints = URI:http://localhost/crl.crl [v3_client] subjectAltName = email:copy basicConstraints = critical,CA:false nsComment = "Client certificate CACHE" nsCertType = client, email, objsign keyUsage = critical,digitalSignature, nonRepudiation, keyEncipherment, keyAgreement crlDistributionPoints = URI:http://localhost/crl.crl
# [req] distinguished_name = req_distinguished_name prompt = no extensions = v3_req [req_distinguished_name] # C=MD # ST=Moldova # L=Chisinau # O=abc # OU=zxc # (, ) CN=CACHE # emailAddress=support@abc.md [v3_req] subjectAltName = email:copy keyUsage = critical, keyCertSign, cRLSign basicConstraints = critical, CA:TRUE, pathlen:0 nsComment = "CA certificate CACHE" nsCertType = sslCA, emailCA crlDistributionPoints = URI:http://localhost/crl.crl
# [req] distinguished_name = distinguished_name prompt = no [distinguished_name] C=MD ST=Moldova L=Chisinau O=abc OU=zxc CN=localhost
# [req] distinguished_name = distinguished_name prompt = no [distinguished_name] serialNumber=987654321 CN=superuser emailAddress=my@abc.md
Note: If you wish, you can create an SSL configuration with the name % TELNET / SSL to support SSL in telnet connections.
Note: A full and detailed description of this section can be found in the mod_ssl documentation. Download Apache with SSL support for Windows from here.
... UseCanonicalName Off SSLEngine on SSLCertificateFile C:/SSLKeys/servercrt.pem SSLCertificateKeyFile C:/SSLKeys/serverkey.pem SSLCACertificateFile C:/SSLKeys/cacrt.pem SSLVerifyClient require SSLVerifyDepth 10 SSLCipherSuite TLSv1:SSLv3:!ADH:!LOW:!EXP:@STRENGTH SSLOptions +StdEnvVars ... LoadModule ssl_module modules/mod_ssl.so ...
httpd.exe -k restart -n CACHEhttpd -c "Listen 8972"
Class sqlru.testpage Extends %ZEN.Component.page
{
/// This XML block defines the contents of this page.
XData Contents [ XMLNamespace = "www.intersystems.com/zen" ]
{
< page xmlns = "www.intersystems.com/zen" title = "" >
< textarea id = "ta" value = "test" rows = "10" cols = "50" />
</ page >
}
Method %OnAfterCreatePage() As %Status
{
if %request. CgiEnvs ( "SERVER_SOFTWARE" )[ "Apache" {
set a = %request. CgiEnvs ( "SSL_CLIENT_S_DN" )
} else {
set a = %request. CgiEnvs ( "CERT_SUBJECT" )
}
do .. %SetValueById ( "ta" ,a)
Quit $$$OK
}
}
var db = new CacheConnection("Server = localhost; Port = 1972; Namespace = SAMPLES; Password = SYS; User ID = _SYSTEM; SSL=true;"); if (db.State == ConnectionState.Closed) { db.Open(); textBox1.Text = db.ServerZV; } db.Close();
keytool -importcert -alias CACHE -file c:\SSLKeys\ca.cer -keystore truststore -storepass mysecret
or keytool -importcert -alias CACHE -file c:\SSLKeys\ca.cer -keystore cacerts -storepass changeit
protocol=SSLv3 keyStore=C:/SSLKeys/client_pwd.pfx keyStoreType=PKCS12 keyStorePassword=mysecret keyRecoveryPassword=mysecret # ca cacerts, trustStore=C:/SSLKeys/truststore trustStoreType=JKS trustStorePassword=mysecret
Note: More detailed information can be found in the JSSE documentation.
package test; import java.sql.Connection; import com.intersys.jdbc.CacheDataSource; public class Test { public static void main(String[] args) throws Throwable { String url = "jdbc:Cache://localhost:1972/USER"; String username = "_SYSTEM"; String password = "SYS"; System.setProperty("com.intersys.SSLConfigFile", "C:/SSLKeys/SSLConfig.Properties"); CacheDataSource cs = new CacheDataSource(); cs.setURL(url); cs.setUser(username); cs.setPassword(password); cs.setConnectionSecurityLevel(10); Connection cn = cs.getConnection(); System.out.println(" !"); //Database db = CacheDatabase.getDatabase(cn); } }
Source: https://habr.com/ru/post/144310/