|
|||
1. Security Services (Overview) Part II System, File, and Device Security 2. Managing Machine Security (Overview) 3. Controlling Access to Systems (Tasks) 4. Virus Scanning Service (Tasks) 5. Controlling Access to Devices (Tasks) 6. Using the Basic Audit Reporting Tool (Tasks) 7. Controlling Access to Files (Tasks) Part III Roles, Rights Profiles, and Privileges 8. Using Roles and Privileges (Overview) 9. Using Role-Based Access Control (Tasks) 10. Role-Based Access Control (Reference) Part IV Solaris Cryptographic Services 13. Solaris Cryptographic Framework (Overview) 14. Solaris Cryptographic Framework (Tasks) Using the Cryptographic Framework (Task Map) Protecting Files With the Solaris Cryptographic Framework (Task Map) Administering the Cryptographic Framework (Task Map) Administering the Cryptographic Framework 15. Solaris Key Management Framework Part V Authentication Services and Secure Communication 16. Using Authentication Services (Tasks) 19. Using Solaris Secure Shell (Tasks) 20. Solaris Secure Shell (Reference) 21. Introduction to the Kerberos Service 22. Planning for the Kerberos Service 23. Configuring the Kerberos Service (Tasks) 24. Kerberos Error Messages and Troubleshooting 25. Administering Kerberos Principals and Policies (Tasks) 26. Using Kerberos Applications (Tasks) 27. The Kerberos Service (Reference) 28. Solaris Auditing (Overview) 29. Planning for Solaris Auditing 30. Managing Solaris Auditing (Tasks) |
Protecting Files With the Solaris Cryptographic FrameworkThis section describes how to generate symmetric keys, how to create checksums for file integrity, and how to protect files from eavesdropping. The commands in this section can be run by regular users. Developers can write scripts that use these commands. How to Generate a Symmetric Key by Using the dd CommandA key is needed to encrypt files and to generate the MAC of a file. The key should be derived from a random pool of numbers. To create the key, you have three options:
Example 14-1 Creating a Key for the AES AlgorithmIn the following example, a secret key for the AES algorithm is created. The key is also stored for later decryption. AES mechanisms use a 128-bit key. The key is expressed as 16 bytes in the dd command. % ls -al ~/keyf drwx------ 2 jdoe staff 512 May 3 11:32 ./ % dd if=/dev/urandom of=$HOME/keyf/05.07.aes16 bs=16 count=1 % chmod 400 ~/keyf/05.07.aes16 Example 14-2 Creating a Key for the DES AlgorithmIn the following example, a secret key for the DES algorithm is created. The key is also stored for later decryption. DES mechanisms use a 64-bit key. The key is expressed as 8 bytes in the dd command. % dd if=/dev/urandom of=$HOME/keyf/05.07.des8 bs=8 count=1 % chmod 400 ~/keyf/05.07.des8 Example 14-3 Creating a Key for the 3DES AlgorithmIn the following example, a secret key for the 3DES algorithm is created. The key is also stored for later decryption. 3DES mechanisms use a 192-bit key. The key is expressed as 24 bytes in the dd command. % dd if=/dev/urandom of=$HOME/keyf/05.07.3des.24 bs=24 count=1 % chmod 400 ~/keyf/05.07.3des.24 Example 14-4 Creating a Key for the MD5 AlgorithmIn the following example, a secret key for the MD5 algorithm is created. The key is also stored for later decryption. The key is expressed as 64 bytes in the dd command. % dd if=/dev/urandom of=$HOME/keyf/05.07.mack64 bs=64 count=1 % chmod 400 ~/keyf/05.07.mack64 How to Generate a Symmetric Key by Using the pktool CommandSome applications require a symmetric key for encryption and decryption of communications. In this procedure, you create a symmetric key and store it.
Example 14-5 Creating a Symmetric Key by Using the pktool CommandIn the following example, a user creates a PKCS #11 keystore for the first time, and then generates a large symmetric key for an application. Finally, the user verifies that the key is in the keystore. # pktool setpin Create new passphrase:easily-remembered-hard-to-detect-password Re-enter new passphrase:Retype password Passphrase changed. % pktool genkey label=specialappkey keytype=generic keylen=1024 Enter PIN for Sun Software PKCS#11 softtoken :Type password % pktool list objtype=key Enter PIN for Sun Software PKCS#11 softtoken :Type password Found 1 keys. Key #1 - symmetric: specialappkey (1024 bits) Example 14-6 Creating a DES Key by Using the pktool CommandIn the following example, a secret key for the DES algorithm is created. The key is stored in a local file for later decryption. The command protects the file with 400 permissions. When the key is created, the print=y option displays the generated key in the terminal window. DES mechanisms use a 64-bit key. The user who owns the keyfile retrieves the key by using the od command. % pktool genkey keystore=file outkey=64bit.file1 keytype=des print=y Key Value ="a3237b2c0a8ff9b3" % od -x 64bit.file1 0000000 a323 7b2c 0a8f f9b3 Example 14-7 Creating a Symmetric Key for IPsec Security AssociationsIn the following example, the administrator manually creates the keying material for IPsec SAs and stores them in files. Then, the administrator copies the keys to the /etc/inet/secret/ipseckeys file and destroys the original files.
How to Compute a Digest of a FileWhen you compute a digest of a file, you can check to see that the file has not been tampered with by comparing digest outputs. A digest does not alter the original file.
Example 14-8 Computing a Digest With the MD5 MechanismIn the following example, the digest command uses the MD5 mechanism to compute a digest for an email attachment. % digest -v -a md5 email.attach >> $HOME/digest.emails.05.07 % cat ~/digest.emails.05.07 md5 (email.attach) = 85c0a53d1a5cc71ea34d9ee7b1b28b01 When the -v option is not used, the digest is saved with no accompanying information: % digest -a md5 email.attach >> $HOME/digest.emails.05.07 % cat ~/digest.emails.05.07 85c0a53d1a5cc71ea34d9ee7b1b28b01 Example 14-9 Computing a Digest With the SHA1 MechanismIn the following example, the digest command uses the SHA1 mechanism to provide a directory listing. The results are placed in a file. % digest -v -a sha1 docs/* > $HOME/digest.docs.legal.05.07 % more ~/digest.docs.legal.05.07 sha1 (docs/legal1) = 1df50e8ad219e34f0b911e097b7b588e31f9b435 sha1 (docs/legal2) = 68efa5a636291bde8f33e046eb33508c94842c38 sha1 (docs/legal3) = 085d991238d61bd0cfa2946c183be8e32cccf6c9 sha1 (docs/legal4) = f3085eae7e2c8d008816564fdf28027d10e1d983 How to Compute a MAC of a FileA message authentication code, or MAC, computes a digest for the file and uses a secret key to further protect the digest. A MAC does not alter the original file.
Example 14-10 Computing a MAC With DES_MAC and a PassphraseIn the following example, the email attachment is authenticated with the DES_MAC mechanism and a key that is derived from a passphrase. The MAC listing is saved to a file. If the passphrase is stored in a file, the file should not be readable by anyone but the user. % mac -v -a des_mac email.attach Enter key: <Type passphrase> des_mac (email.attach) = dd27870a % echo "des_mac (email.attach) = dd27870a" >> ~/desmac.daily.05.07 Example 14-11 Computing a MAC With MD5_HMAC and a Key FileIn the following example, the email attachment is authenticated with the MD5_HMAC mechanism and a secret key. The MAC listing is saved to a file. % mac -v -a md5_hmac -k $HOME/keyf/05.07.mack64 email.attach md5_hmac (email.attach) = 02df6eb6c123ff25d78877eb1d55710c % echo "md5_hmac (email.attach) = 02df6eb6c123ff25d78877eb1d55710c" \ >> ~/mac.daily.05.07 Example 14-12 Computing a MAC With SHA1_HMAC and a Key FileIn the following example, the directory manifest is authenticated with the SHA1_HMAC mechanism and a secret key. The results are placed in a file. % mac -v -a sha1_hmac \ -k $HOME/keyf/05.07.mack64 docs/* > $HOME/mac.docs.legal.05.07 % more ~/mac.docs.legal.05.07 sha1_hmac (docs/legal1) = 9b31536d3b3c0c6b25d653418db8e765e17fe07a sha1_hmac (docs/legal2) = 865af61a3002f8a457462a428cdb1a88c1b51ff5 sha1_hmac (docs/legal3) = 076c944cb2528536c9aebd3b9fbe367e07b61dc7 sha1_hmac (docs/legal4) = 7aede27602ef6e4454748cbd3821e0152e45beb4 Example 14-13 Computing a MAC With SHA1_HMAC and a Key LabelIn the following example, the directory manifest is authenticated with the SHA1_HMAC mechanism and a secret key. The results are placed in the user's PKCS #11 keystore. The user initially created the keystore and the password to the keystore by using the pktool setpin command. % mac -a sha1_hmac -K legaldocs0507 docs/* Enter pin for Sun Software PKCS#11 softtoken:Type password To retrieve the MAC from the keystore, the user uses the verbose option, and provides the key label and the name of the directory that was authenticated. % mac -v -a sha1_hmac -K legaldocs0507 docs/* Enter pin for Sun Software PKCS#11 softtoken:Type password sha1_hmac (docs/legal1) = 9b31536d3b3c0c6b25d653418db8e765e17fe07a sha1_hmac (docs/legal2) = 865af61a3002f8a457462a428cdb1a88c1b51ff5 sha1_hmac (docs/legal3) = 076c944cb2528536c9aebd3b9fbe367e07b61dc7 sha1_hmac (docs/legal4) = 7aede27602ef6e4454748cbd3821e0152e45beb4 How to Encrypt and Decrypt a FileWhen you encrypt a file, the original file is not removed or changed. The output file is encrypted. For solutions to common errors from the encrypt command, see the section that follows the examples.
Example 14-14 Creating an AES Key for Encrypting Your FilesIn the following example, a user creates and stores an AES key in an existing PKCS #11 keystore for use in encryption and decryption. The user can verify that the key exists and can use the key, but cannot view the key itself. % pktool genkey label=MyAESkeynumber1 keytype=aes keylen=256 Enter PIN for Sun Software PKCS#11 softtoken :Type password % pktool list objtype=key Enter PIN for Sun Software PKCS#11 softtoken :<Type password> Found 1 key Key #1 - Sun Software PKCS#11 softtoken: MyAESkeynumber1 (256) To use the key to encrypt a file, the user retrieves the key by its label. % encrypt -a aes -K MyAESkeynumber1 -i encryptthisfile -o encryptedthisfile To decrypt the encryptedthisfile file, the user retrieves the key by its label. % decrypt -a aes -K MyAESkeynumber1 -i encryptedthisfile -o sameasencryptthisfile Example 14-15 Encrypting and Decrypting With AES and a PassphraseIn the following example, a file is encrypted with the AES algorithm. The key is generated from the passphrase. If the passphrase is stored in a file, the file should not be readable by anyone but the user. % encrypt -a aes -i ticket.to.ride -o ~/enc/e.ticket.to.ride Enter key: <Type passphrase> The input file, ticket.to.ride, still exists in its original form. To decrypt the output file, the user uses the same passphrase and encryption mechanism that encrypted the file. % decrypt -a aes -i ~/enc/e.ticket.to.ride -o ~/d.ticket.to.ride Enter key: <Type passphrase> Example 14-16 Encrypting and Decrypting With AES and a Key FileIn the following example, a file is encrypted with the AES algorithm. AES mechanisms use a key of 128 bits, or 16 bytes. % encrypt -a aes -k ~/keyf/05.07.aes16 \ -i ticket.to.ride -o ~/enc/e.ticket.to.ride The input file, ticket.to.ride, still exists in its original form. To decrypt the output file, the user uses the same key and encryption mechanism that encrypted the file. % decrypt -a aes -k ~/keyf/05.07.aes16 \ -i ~/enc/e.ticket.to.ride -o ~/d.ticket.to.ride Example 14-17 Encrypting and Decrypting With ARCFOUR and a Key FileIn the following example, a file is encrypted with the ARCFOUR algorithm. The ARCFOUR algorithm accepts a key of 8 bits (1 byte), 64 bits (8 bytes), or 128 bits (16 bytes). % encrypt -a arcfour -i personal.txt \ -k ~/keyf/05.07.rc4.8 -o ~/enc/e.personal.txt To decrypt the output file, the user uses the same key and encryption mechanism that encrypted the file. % decrypt -a arcfour -i ~/enc/e.personal.txt \ -k ~/keyf/05.07.rc4.8 -o ~/personal.txt Example 14-18 Encrypting and Decrypting With 3DES and a Key FileIn the following example, a file is encrypted with the 3DES algorithm. The 3DES algorithm requires a key of 192 bits, or 24 bytes. % encrypt -a 3des -k ~/keyf/05.07.des24 \ -i ~/personal2.txt -o ~/enc/e.personal2.txt To decrypt the output file, the user uses the same key and encryption mechanism that encrypted the file. % decrypt -a 3des -k ~/keyf/05.07.des24 \ -i ~/enc/e.personal2.txt -o ~/personal2.txt TroubleshootingThe following messages indicate that the key that you provided to the encrypt command is not permitted by the algorithm that you are using.
If you pass a key that does not meet the requirements of the algorithm, you must supply a better key.
|
||
|