Skip to content

Commit 7630c4f

Browse files
author
Bill Abt
committed
Added the ability to specify/change the default cipher suite used by OpenSSL.
1 parent a5e822d commit 7630c4f

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,11 @@ Both clients and server require at a minimum the following configuration items:
8585

8686
*Note 3:* For the first two versions of the API, if your `Private key` is included in your certificate file, you can omit this parameter and the API will use the same file name as specified for the certificate file.
8787

88+
*Note 4:* If you desire to customize the cipher suite used, you can do so by setting the `cipherSuite` member after creating the configuration. The default value if not changed is set to `ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL`. See the example below.
89+
8890
#### Example
8991

90-
The following illustrates creating a configuration using the second form of the API above using a self-signed certificate file as the key file and not supplying a certificate chain file:
92+
The following illustrates creating a configuration using the second form of the API above using a self-signed certificate file as the key file and not supplying a certificate chain file. It also illustrates setting the cipher suite to `ALL` from the default:
9193
```swift
9294
import SSLService
9395

@@ -98,6 +100,8 @@ let myKeyPath = "/opt/myApp/config/myKeyFile.pem"
98100

99101
let myConfig = SSLService.Configuration(withCACertificateDirectory: nil, usingCertificateFile: myCertPath, withKeyFile: myKeyFile)
100102

103+
myConfig.cipherSuite = "ALL"
104+
101105
...
102106

103107
```

Sources/SSLService.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ public class SSLService : SSLServiceDelegate {
6262
/// True if using `self-signed` certificates.
6363
public private(set) var certsAreSelfSigned = false
6464

65+
/// Cipher suite to use. Defaults to `ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL`
66+
public var cipherSuite: String = "ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL"
67+
6568
// MARK: Lifecycle
6669

6770
///
@@ -506,7 +509,7 @@ public class SSLService : SSLServiceDelegate {
506509
}
507510

508511
// Handle the stuff common to both client and server...
509-
SSL_CTX_set_cipher_list(context, "ALL")
512+
SSL_CTX_set_cipher_list(context, self.configuration.cipherSuite)
510513
if self.configuration.certsAreSelfSigned {
511514
SSL_CTX_set_verify(context, SSL_VERIFY_NONE, nil)
512515
} else {

0 commit comments

Comments
 (0)