Class BaseX509KeyManager
java.lang.Object
org.postgresql.ssl.BaseX509KeyManager
- All Implemented Interfaces:
KeyManager, X509KeyManager
- Direct Known Subclasses:
PEMKeyManager, PKCS12KeyManager
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionchooseClientAlias(String[] keyType, Principal[] principals, Socket socket) chooseServerAlias(String s, Principal[] principals, Socket socket) String[]getClientAliases(String keyType, Principal[] principals) String[]getServerAliases(String s, Principal[] principals) private static booleanhasInsecurePosixPermissions(Set<PosixFilePermission> permissions, boolean isOwnedByRoot) Determines whether the given POSIX permissions are insecure for a private key file.private static booleanisFileOwnedByRoot(Path keyPath) Checks whether the file is owned by root (uid 0).voidgetCertificateChain and getPrivateKey cannot throw exceptions, therefore any exception is stored inerrorand can be raised by this method.static voidvalidateKeyFilePermissions(Path keyPath) Validates that the private key file has secure permissions, matching libpq behavior.private static booleanvalidatePosixPermissions(Path keyPath) Validates POSIX file permissions of key, matching libpq behavior.private static booleanvalidateWindowsAclPermissions(Path keyPath) Validates Windows ACL permissions of the key file.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface X509KeyManager
getCertificateChain, getPrivateKey
-
Field Details
-
ROOT_UID
private static final int ROOT_UID- See Also:
-
error
-
-
Constructor Details
-
BaseX509KeyManager
public BaseX509KeyManager()
-
-
Method Details
-
throwKeyManagerException
getCertificateChain and getPrivateKey cannot throw exceptions, therefore any exception is stored inerrorand can be raised by this method.- Throws:
PSQLException- if any exception is stored inerrorand can be raised
-
getClientAliases
- Specified by:
getClientAliasesin interfaceX509KeyManager
-
chooseClientAlias
- Specified by:
chooseClientAliasin interfaceX509KeyManager
-
getServerAliases
- Specified by:
getServerAliasesin interfaceX509KeyManager
-
chooseServerAlias
- Specified by:
chooseServerAliasin interfaceX509KeyManager
-
validateKeyFilePermissions
Validates that the private key file has secure permissions, matching libpq behavior. On POSIX systems, root-owned files are allowed group-read access (up to 0640), since it's common for root to own certs and grant read access via group membership. Files owned by anyone else must be 0600 or stricter. On Windows, ACLs are checked to ensure only the owner and trusted system accounts have access.- Parameters:
keyPath- the path to the private key file- Throws:
PSQLException- if the file has insecure permissions
-
validatePosixPermissions
Validates POSIX file permissions of key, matching libpq behavior. Root-owned files (uid 0) allow GROUP_READ (up to 0640). Non-root-owned files require 0600 or less (no group or other permissions).- Parameters:
keyPath- the path to the private key file- Returns:
- true if validation succeeded (permissions are secure), false if POSIX is not supported
- Throws:
PSQLException- if the file has insecure permissions
-
isFileOwnedByRoot
Checks whether the file is owned by root (uid 0). Falls back to false if the unix:uid attribute is not available.- Throws:
IOException
-
hasInsecurePosixPermissions
private static boolean hasInsecurePosixPermissions(Set<PosixFilePermission> permissions, boolean isOwnedByRoot) Determines whether the given POSIX permissions are insecure for a private key file. Matches libpq behavior: root-owned files allow GROUP_READ (0640), while non-root-owned files reject all group and other permissions (0600). -
validateWindowsAclPermissions
Validates Windows ACL permissions of the key file.- Parameters:
keyPath- the path to the private key file- Returns:
- true if validation succeeded (permissions are secure), false if ACL is not supported
- Throws:
PSQLException- if the file has insecure permissions
-