Package protocol implements ASN.1 wire protocol definitions and codecs for directory services, as defined in RFC 4511, ITU-T rec. X.511, et al. In particular, "request", "response" and "control" components represent the bulk of this package.
This package was designed specifically for use by the Go Directory Project.
This package is released under the terms of the MIT license. See the LICENSE file in the repository root for details.
This package is undergoing heavy development and is prone to breaking changes at any time. It is not yet suitable for use in any production environment.
The protocol package and its included package subdirectories ("request", etc) are regarded as "mid rank" packages, in that they "sit" between "high rank" packages such as "dsa" and "low rank" packages such as "common" and "encoding".
The protocol package defines types based upon the various "request" and "response" ASN.1 constructs observed throughout the aforementioned documents. These constructs are used by an entity -- often a DSA or a DUA -- for communicating via the relevant directory protocol(s).
For example, a client -- via a DUA -- wishes to perform a search of their local directory service. This would require the following of the requesting party:
- Connect to the DSA, likely involving TLS
- Construct a
BindRequestRFC4511 type (bearing the[APPLICATION 0]ASN.1 tag) - Add the
BindRequestas the "ProtocolOp" component of anLDAPMessage, possibly including LDAP Control instructions - Encode the
LDAPMessageas ASN.1 BER according to RFC4511 - Write the encoding to the DSA connection for transmittal
- Await DSA response
The DSA, upon receipt of the above payload, is expected to take the following actions:
- Decode
LDAPMessagepayload, determine kind of "ProtocolOp" - De-envelope the
BindRequestand process it (for the purposes of this example, it is assumed the request is legitimate) - Prepare an
LDAPMessage, except the "ProtocolOp" is aBindResponsewhich circumscribes an LDAP Result Code of zero (0) for success - Encode the
LDAPMessageenvelope payload - Write the encoding to the connection established by the DUA
- Await further instructions
Only once a successful BindResponse is received can the requesting party submit the desired SearchRequest.
The purpose of this package is wire protocol exchanges not unlike the above, whether these exchanges occur between a DUA and DSA, or between multiple DSAs.
For example:
var bind BindRequest
// add credentials, SASL mechanisms, etc., if needed
var req LDAPMessage
req.ProtocolOp = bind
// Optionally add controls
encoding, err := req.Encode()
// check error
// Write to encoding connection, e.g.:
_, err := r.conn.Write(encoding)
//////////////////////////////////
// Wait for encoded reply from DSA
//////////////////////////////////
var resp LDAPMessage
err = resp.Decode(replyBytes)
// check error
bresp, ok := resp.ProtocolOp.(BindResponse)
// check bind response
// if OK, continue with other request/response exchanges
// as needed...