aboutsummaryrefslogtreecommitdiff
path: root/goldap/bind_request.go
diff options
context:
space:
mode:
authorQuentin Dufour <quentin@deuxfleurs.fr>2021-07-07 01:49:33 +0200
committerQuentin Dufour <quentin@deuxfleurs.fr>2021-09-16 13:09:26 +0200
commit563fc272a36c8be317fbe95c8308ca2dfa29c3aa (patch)
tree0b6f9a6a15516e7234fc928ecbebbd32d3154074 /goldap/bind_request.go
parentaa912b5ceb24cb8772709171ea9589b0771bbe54 (diff)
downloadbottin-563fc272a36c8be317fbe95c8308ca2dfa29c3aa.tar.gz
bottin-563fc272a36c8be317fbe95c8308ca2dfa29c3aa.zip
Vendor goldap, fix ASN.1 BER integer and length encoding
- Add tests for goldap to prevent regressions - Disable reconnection for our functional tests
Diffstat (limited to 'goldap/bind_request.go')
-rw-r--r--goldap/bind_request.go93
1 files changed, 93 insertions, 0 deletions
diff --git a/goldap/bind_request.go b/goldap/bind_request.go
new file mode 100644
index 0000000..d00a3ef
--- /dev/null
+++ b/goldap/bind_request.go
@@ -0,0 +1,93 @@
+package message
+
+import "fmt"
+
+// BindRequest ::= [APPLICATION 0] SEQUENCE {
+// version INTEGER (1 .. 127),
+// name LDAPDN,
+// authentication AuthenticationChoice }
+
+func (request *BindRequest) Name() LDAPDN {
+ return request.name
+}
+
+func (request *BindRequest) Authentication() AuthenticationChoice {
+ return request.authentication
+}
+
+func (request *BindRequest) AuthenticationSimple() OCTETSTRING {
+ return request.Authentication().(OCTETSTRING)
+}
+
+func (request *BindRequest) AuthenticationChoice() string {
+ switch request.Authentication().(type) {
+ case OCTETSTRING:
+ return "simple"
+ case SaslCredentials:
+ return "sasl"
+ }
+ return ""
+}
+
+func readBindRequest(bytes *Bytes) (bindrequest BindRequest, err error) {
+ err = bytes.ReadSubBytes(classApplication, TagBindRequest, bindrequest.readComponents)
+ if err != nil {
+ err = LdapError{fmt.Sprintf("readBindRequest:\n%s", err.Error())}
+ return
+ }
+ return
+}
+
+func (request *BindRequest) readComponents(bytes *Bytes) (err error) {
+ request.version, err = readINTEGER(bytes)
+ if err != nil {
+ err = LdapError{fmt.Sprintf("readComponents:\n%s", err.Error())}
+ return
+ }
+ if !(request.version >= BindRequestVersionMin && request.version <= BindRequestVersionMax) {
+ err = LdapError{fmt.Sprintf("readComponents: invalid version %d, must be between %d and %d", request.version, BindRequestVersionMin, BindRequestVersionMax)}
+ return
+ }
+ request.name, err = readLDAPDN(bytes)
+ if err != nil {
+ err = LdapError{fmt.Sprintf("readComponents:\n%s", err.Error())}
+ return
+ }
+ request.authentication, err = readAuthenticationChoice(bytes)
+ if err != nil {
+ err = LdapError{fmt.Sprintf("readComponents:\n%s", err.Error())}
+ return
+ }
+ return
+}
+
+func (request BindRequest) write(bytes *Bytes) (size int) {
+ switch request.authentication.(type) {
+ case OCTETSTRING:
+ size += request.authentication.(OCTETSTRING).writeTagged(bytes, classContextSpecific, TagAuthenticationChoiceSimple)
+ case SaslCredentials:
+ size += request.authentication.(SaslCredentials).writeTagged(bytes, classContextSpecific, TagAuthenticationChoiceSaslCredentials)
+ default:
+ panic(fmt.Sprintf("Unknown authentication choice: %#v", request.authentication))
+ }
+ size += request.name.write(bytes)
+ size += request.version.write(bytes)
+ size += bytes.WriteTagAndLength(classApplication, isCompound, TagBindRequest, size)
+ return
+}
+
+func (request BindRequest) size() (size int) {
+ size += request.version.size()
+ size += request.name.size()
+ switch request.authentication.(type) {
+ case OCTETSTRING:
+ size += request.authentication.(OCTETSTRING).sizeTagged(TagAuthenticationChoiceSimple)
+ case SaslCredentials:
+ size += request.authentication.(SaslCredentials).sizeTagged(TagAuthenticationChoiceSaslCredentials)
+ default:
+ panic(fmt.Sprintf("Unknown authentication choice: %#v", request.authentication))
+ }
+
+ size += sizeTagAndLength(TagBindRequest, size)
+ return
+}