Commands for invoking the Security Service Provider Interface
This module is still experimental and liable to change.
This package includes procedures related to the Security Service Provider Interface (SSPI) on the Windows platforms. For commands for other cryptographic operations, refer to the CryptoAPI documentation.
The Security Support Provider Interface is a standard interface to various security protocols that provide for security functions such as authentication, encryption and integrity. The SSPI interface allows establishment of a security context that can be used for signing and encrypting data passed between a client and a server.
This module currently supports only the Negotiate, NTLM, Kerberos, SChannel and Microsoft Unified Security Protocol Provider packages.
On the client side, the application program starts off by retrieving the credentials to be used to authenticate itself to the server by calling sspi_acquire_credentials with the -role client option. It then creates a new client security context by calling sspi_client_context specifying appropriate desired security characteristics. The application then exchanges messages with the server to complete the authentication.
Depending on the security protocol in use, the authentication between the client and the server may require multiple message exchanges between the client and the server. Once it obtains its security context, the client calls sspi_step passing it the security context. This command returns an indication of whether the authentication is complete, or more exchanges with the server are required. In the latter case, data returned by the command is sent to the server and the server response is passed back to the command. This sequence is repeated until the command indicates the authentication is complete or generates a Tcl exception indicating authentication failure. The security context generated in this manner can then be used to sign and encrypt messages between the client and the server.
On the server side, the application program starts off by retrieving its own credentials by calling sspi_acquire_credentials with the -role server. It then creates a new server security context by calling sspi_server_context passing it the authentication data sent by the client. The server then enters the authentication loop described below. From this point on, the server follows the authentication loop calling sspi_step in the same manner as described above for the client.
Once a security context is established, either on the client or the server, its characteristics, including the negotiated parameters, security principal name etc. can be retrieved through commands sspi_context_features, sspi_context_username and sspi_context_sizes. In the case of SSL/SChannel based providers, the sspi_local_cert and sspi_remote_cert return the certificates in use for a connection. Note that not all commands are supported by all security providers.
The security context should be released when no longer needed. For schannel based providers only, first call sspi_shutdown_context and pass any returned data to the remote peer. Then call sspi_delete_context to release context releases. For other providers, only sspi_delete_context should be called.
Similarly, when no longer required, both the server and client ends should free resources associated with their credentials by calling sspi_free_credentials.
Once a security context has been completely created as above, it can then be used to generate and verify messages signatures using sspi_sign and sspi_verify_signature respectively.
Similarly, the security context can be used to encrypt and decrypt messages using sspi_encrypt and sspi_decrypt.
For SSPI stream contexts, the commands sspi_encrypt_stream and sspi_decrypt_stream encrypt and decrypt streaming data. Alternately the sspi_encrypt_and_write command can be used to directly write encrypted data to a channel.
-credentials CREDENTIALS | Specifies the credentials to which a handle is to be returned. If unspecified the default credentials for the package are used. For NTLM or Negotiate providers, the sspi_winnt_identity_credentials should be used to return non-default credentials in the appropriate format. For SSL/Schannel based providers, the sspi_schannel_credentials should be used for the same purpose. |
-getexpiration | If specified, the expiration time for the returned credentials is also returned. See description of command return value above. |
-package SECURITYPACKAGE | Specifies the security package with which the credentials are to be used. By default, this is NTLM. The list of available security packages on a system can be obtained through sspi_enumerate_packages. |
-principal PRINCIPAL | Specifies the name of the principal whose credentials are to be referenced. By default, this is the user account under which the process is running. |
-role ROLE | Indicates how the credentials will be used, based on ROLE - client or outbound for clients, server or inbound for servers and both (default) if credentials are used for both purposes. Note that SSL/SChannel based providers require separate client and server credentials and both is not a valid option for them. |
-confidentiality BOOL | If specified as true, messages are to be encrypted. |
-connection BOOL | If specified as true, the security context will not handle formatting of messages. |
-datarep DATAREP | Specifies the data representation on the target. DATAREP must be either network (default) or native. |
-delegate BOOL | If specified as true, the server can use the context to other servers as the client. Requires -mutualauth to also be specified as true. |
-extendederror BOOL | When true, the remote end is notified of errors. Note that several Windows versions, including Windows 7, may experience SSL/TLS negotiation failures when this option is specified. See Microsoft Knowledgebase article KB975858 for details. |
-integrity BOOL | If specified as true, messages are to be signed. |
-manualvalidation BOOL | If BOOL is false (default), SChannel based providers will validate the remote server's certificate. If specified as true, the provider will not validate the received certificate. It is the caller's responsibility to do so. The remote certificate can be retrieved with sspi_remote_cert and verified as described in Certificate verification. |
-mutualauth BOOL | If specified as true, both the client and server are to be authenticated. |
-replaydetect BOOL | If specified as true, detection of replayed messages is desired. |
-sequencedetect BOOL | If specified as true, detection of out-of-sequence messages is desired. |
-stream BOOL | If specified as true, indicates a stream oriented connection. |
-target TARGET | Specifies the target of the security context. The format depends on the security service provider. In the case of a SSL/SChannel based provider, this is generally the name that should match the subject name in the certificate sent by the server. |
-usesessionkey BOOL | If specified as true, a new session key must be negotiated. |
-confidentiality | If true, encryption is supported. |
-connection | If true, the security context will not handle formatting of messages. |
-delegate | If true, the server can use the context to other servers as the client. |
-extendederror | If true, the remote end is notified of errors. |
-integrity | If true, messages signing is supported. |
-mutualauth | If true, both the client and server are authenticated. |
-replaydetect | If true, detection of replayed messages is enabled. |
-sequencedetect | If true, detection of out-of-sequence messages is enabled. |
-stream | If true, indicates a stream oriented connection. |
-maxtoken | Maximum size of token used in the authentication exchange. |
-maxsig | Maximum size of signature. |
-blocksize | Messages should preferably be a multiple of this value. |
-trailersize | Size of security trailer to be appended to messages. |
-seqnum SEQNUM | The sequence number expected in the message. Must not be specified when CONTEXT is using the Digest SSP package or if the transport does not maintain sequence numbers. |
-qop INTEGER | Package specific flags that indicate quality of protection desired. Must be unspecified or 0 if the Digest SSP package is used. |
-seqnum SEQNUM | The sequence number to use for the message. Must not be specified when CONTEXT is using the Digest SSP package or if the transport does not maintain sequence numbers. |
-qop INTEGER | Package specific flags that indicate quality of protection desired. Must be unspecified or 0 if the Digest SSP package is used. |
-all | Same as all options being specified. |
-capabilities | A list of tokens that describe the capabilties of the provider. |
-comment | A comment describing the provider. |
-rpcid | A DCE RPC identifier, if supported. |
-maxtokensize | Maximum size of a security token. |
-name | Name of the provider. |
-version | The version of the provider interface. |
-confidentiality BOOL | If specified as true, messages are to be encrypted. |
-connection BOOL | If specified as true, the security context will not handle formatting of messages. |
-datarep DATAREP | Specifies the data representation on the target. DATAREP must be either network (default) or native. |
-delegate BOOL | If specified as true, the server can use the context to other servers as the client. Requires -mutualauth to also be specified as true. |
-extendederror BOOL | When true, the remote end is notified of errors. |
-integrity BOOL | If specified as true, messages are to be signed. |
-mutualauth BOOL | If specified as true, both the client and server are to be authenticated. |
-replaydetect BOOL | If specified as true, detection of replayed messages is desired. |
-sequencedetect BOOL | If specified as true, detection of out-of-sequence messages is desired. |
-stream BOOL | If specified as true, indicates a stream oriented connection. |
-certificates CERTLIST | CERTLIST is a list of certificate context handles with private keys that are used to authenticate the application. Each handle corresponds to a key exchange method supported by the application. On the client end, this need not be specified in which case the provider will find an appropriate certificate if needed. |
-cipherstrength CIPHERSTRENGTH | Specifies the strength of the block ciphers to be used in connections using the returned credentials. CIPHERSTRENGTH is list of one or two elements. The first element is the minimum number of bits required in the negotiated encryption key. The second element is the maximum number of bits in the key and defaults to the minimum number of bits if the list contains only one element. A value of 0 indicates a system-specific default to be used. A value of -1 indicates a null cipher (no encryption but with message authentication). This should be used only for debugging purposes. |
-protocols PROTOCOLLIST | Specifies the protocols that are acceptable for a connection using the returned credentials. PROTOCOLLIST is a list of one or more of the following: ssl2, ssl3, tls1, tls1.1 and tls1.2. If unspecified, or if PROTOCOLLIST is an empty list, defaults to the list of protocols configured in the system registry. |
-rootstore HSTORE | Specifies a handle to an additional certificate root store that contains root certificates to authenticate incoming client connections. This is only used by server applications which need to authenticate clients. |
-sessionlifespan MILLISECS | Specifies the number of milliseconds that a Schannel session should be cached. New connections after this time will require a new session. A value of 0 (default) indicates the system-specific default is to be used. |
done | Indicates that the security context negotiation is completed. The application can use it for cryptographic operations such as signing or encryption. |
continue | The security context negotiation is in progress. Additional steps are required in the negotiation process and sspi_step must be called again with additional data received from the remote end. |
disconnected | The negotiation is terminated and cannot be used for cryptographic operations. Caller should delete the context using sspi_delete_context. |
Copyright © 2007-2013 Ashok P. Nadkarni