java.security Scala Native implementation based on OpenSSL
You need to add the dependency to your Scala Native project.
On SBT:
libraryDependencies += "com.github.lolgab" %%% "scala-native-crypto" % "x.y.z"On Mill:
def ivyDeps = super.ivyDeps() ++ Agg(ivy"com.github.lolgab::scala-native-crypto::x.y.z")You need also to install OpenSSL:
On Debian/Ubuntu:
sudo apt install libssl-dev
On macOS (with Homebrew):
brew install openssl
On Windows (with vcpkg):
# Global `vcpkg`
vcpkg install openssl
# In workspace (we've added `openssl` to `vcpkg.json`)
vcpkg install
And you need to have libcrypto in your linking path (e.g., libcrypto.so on Linux, libcrypto.dylib on macOS, and libcrypto*.dll + libcrypto.lib on Windows).
For custom openssl build, you will need to add the path via nativeLinkingOptions.
On SBT:
nativeConfig ~= { c => c.withLinkingOptions(c.nativeLinkingOptions :+ "-L/opt/custom/openssl@3/lib") }On Mill:
def nativeLinkingOptions = super.nativeLinkingOptions() ++ Seq("-L/opt/custom/openssl@3/lib")According JDK Security Algorithm Implementation Requirements, the following classes and algorithm checked are implemented and those unchecked are minimal requirements for interoperable JDK shims.
Welcome contributions to implement the missing algorithms/classes!
(The sequence is in the same order of the reference table)
java.security..AlgorithmParameterGenerator- DiffieHellman (1024, 2048)
- DSA (1024, 2048)
java.security.AlgorithmParameters- AES
- ChaCha20-Poly1305
- DESede
- DiffieHellman
- DSA
- EC (secp256r1, secp384r1)
- RSASSA-PSS (MGF1 mask generation function and SHA-256 or SHA-384 hash algorithms)
java.security.cert.CertificateFactory- X.509
- with known issues
- X.509
java.security.cert.CertPathEncoding- PKCS7
- PkiPath
java.security.cert.CertPathBuilder- PKIX
java.security.cert.CertPathValidator- PKIX
java.security.cert.CertStore- Collection
javax.crypto.Cipher- AES/CBC/NoPadding (128)
- AES/CBC/PKCS5Padding (128)
- AES/ECB/NoPadding (128)
- AES/ECB/PKCS5Padding (128)
- AES/GCM/NoPadding (128, 256)
- ChaCha20-Poly1305
- DESede/CBC/NoPadding (168)
- DESede/CBC/PKCS5Padding (168)
- DESede/ECB/NoPadding (168)
- DESede/ECB/PKCS5Padding (168)
- RSA/ECB/PKCS1Padding (1024, 2048)
- RSA/ECB/OAEPWithSHA-1AndMGF1Padding (1024, 2048)
- RSA/ECB/OAEPWithSHA-256AndMGF1Padding (1024, 2048)
javax.crypto.KeyAgreement- DiffieHellman
- ECDH (secp256r1, secp384r1)
- X25519
java.security.KeyFactory- DiffieHellman
- DSA
- EC
- RSA
- RSASSA-PSS
- X25519
javax.crypto.KeyGenerator- AES (128, 256)
- ChaCha20
- DESede (168)
- HmacSHA1
- HmacSHA256
java.security.KeyPairGenerator- DiffieHellman (1024, 2048, 3072, 4096)
- DSA (1024, 2048)
- EC (secp256r1, secp384r1)
- RSA (1024, 2048, 3072, 4096)
- RSASSA-PSS (2048, 3072, 4096)
- X25519
java.security.KeyStore- PKCS12
- Partially implemented, only supports loading and reading, but not writing for now.
- PKCS12
javax.crypto.Mac- HmacSHA1
- HmacSHA256
- extra
- HmacSHA224
- HmacSHA384
- HmacSHA512
- HmacSHA3-224
- HmacSHA3-256
- HmacSHA3-384
- HmacSHA3-512
java.security.MessageDigest- SHA-1
- SHA-256
- SHA-384
- extra
- SHA3-224
- SHA3-256
- SHA3-384
- SHA3-512
javax.crypto.SecretKeyFactory- DESede
-
java.security.SecureRandom -
java.security.Signature javax.net.ssl.SSLContext: See downstream project lqhuang/scala-native-http- TLSv1.2
- TLSv1.3
javax.net.ssl.KeyManagerFactory: See downstream project lqhuang/scala-native-http- PKIX
javax.net.ssl.TrustManagerFactory: See downstream project lqhuang/scala-native-http- PKIX
- Create a
X500Principalinstance from string / bytes dones't support verification for now- Since OpenSSL doesn't expose individual verification and constructor for ASN1 Distinguished Name. There might have some workaround to hack the verification, for example try to create a fake X509 cert first, but it's not implemented yet.
- The current implementation of
X500Principalconstructor just convert the input string to bytes and store it in RFC standards, without any verification. Basically, we majorly usedgetSubjectX500Principal()method ofX509Certificateto get well formedX500Principalinternally. - Through the
X500Principalconstructor is documented as a public API and can be used to create an instance, WE DON'T RECOMMEND TO USE THE CONSTRUCTOR DIRECTLY UNTIL THE VERIFICATION IS IMPLEMENTED.