Development of an internal social media platform with personalised dashboards for students
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

rfc4511.py 42KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007
  1. """
  2. """
  3. # Created on 2013.05.15
  4. #
  5. # Author: Giovanni Cannata
  6. #
  7. # Copyright 2014 - 2018 Giovanni Cannata
  8. #
  9. # This file is part of ldap3.
  10. #
  11. # ldap3 is free software: you can redistribute it and/or modify
  12. # it under the terms of the GNU Lesser General Public License as published
  13. # by the Free Software Foundation, either version 3 of the License, or
  14. # (at your option) any later version.
  15. #
  16. # ldap3 is distributed in the hope that it will be useful,
  17. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. # GNU Lesser General Public License for more details.
  20. #
  21. # You should have received a copy of the GNU Lesser General Public License
  22. # along with ldap3 in the COPYING and COPYING.LESSER files.
  23. # If not, see <http://www.gnu.org/licenses/>.
  24. #######################
  25. # ldap ASN.1 Definition
  26. # from RFC4511 - Appendix B
  27. # extended with result codes from IANA ldap-parameters as of 2013.08.21
  28. # extended with modify_increment from RFC4525
  29. #########################################################
  30. # Lightweight-Directory-Access-Protocol-V3 {1 3 6 1 1 18}
  31. # -- Copyright (C) The Internet Society (2006). This version of
  32. # -- this ASN.1 module is part of RFC 4511; see the RFC itself
  33. # -- for full legal notices.
  34. # DEFINITIONS
  35. # IMPLICIT TAGS
  36. # EXTENSIBILITY IMPLIED
  37. from pyasn1.type.univ import OctetString, Integer, Sequence, Choice, SequenceOf, Boolean, Null, Enumerated, SetOf
  38. from pyasn1.type.namedtype import NamedTypes, NamedType, OptionalNamedType, DefaultedNamedType
  39. from pyasn1.type.constraint import ValueRangeConstraint, SingleValueConstraint, ValueSizeConstraint
  40. from pyasn1.type.namedval import NamedValues
  41. from pyasn1.type.tag import tagClassApplication, tagFormatConstructed, Tag, tagClassContext, tagFormatSimple
  42. # constants
  43. # maxInt INTEGER ::= 2147483647 -- (2^^31 - 1) --
  44. LDAP_MAX_INT = 2147483647
  45. MAXINT = Integer(LDAP_MAX_INT)
  46. # constraints
  47. rangeInt0ToMaxConstraint = ValueRangeConstraint(0, MAXINT)
  48. rangeInt1To127Constraint = ValueRangeConstraint(1, 127)
  49. size1ToMaxConstraint = ValueSizeConstraint(1, MAXINT)
  50. responseValueConstraint = SingleValueConstraint(0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 14, 16, 17, 18, 19, 20, 21, 32, 33, 34, 36, 48, 49, 50, 51, 52, 53, 54, 64, 65, 66, 67, 68, 69, 71, 80, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123,
  51. 4096)
  52. # custom constraints
  53. numericOIDConstraint = None # TODO
  54. distinguishedNameConstraint = None # TODO
  55. nameComponentConstraint = None # TODO
  56. attributeDescriptionConstraint = None # TODO
  57. uriConstraint = None # TODO
  58. attributeSelectorConstraint = None # TODO
  59. class Integer0ToMax(Integer):
  60. subtypeSpec = Integer.subtypeSpec + rangeInt0ToMaxConstraint
  61. class LDAPString(OctetString):
  62. # LDAPString ::= OCTET STRING -- UTF-8 encoded, -- [ISO10646] characters
  63. encoding = 'utf-8'
  64. class MessageID(Integer0ToMax):
  65. # MessageID ::= INTEGER (0 .. maxInt)
  66. pass
  67. class LDAPOID(OctetString):
  68. # LDAPOID ::= OCTET STRING -- Constrained to <numericoid>
  69. # -- [RFC4512]
  70. # subtypeSpec = numericOIDConstraint
  71. pass
  72. class LDAPDN(LDAPString):
  73. # LDAPDN ::= LDAPString -- Constrained to <distinguishedName>
  74. # -- [RFC4514]
  75. # subtypeSpec = distinguishedName
  76. pass
  77. class RelativeLDAPDN(LDAPString):
  78. # RelativeLDAPDN ::= LDAPString -- Constrained to <name-component>
  79. # -- [RFC4514]
  80. # subtypeSpec = LDAPString.subtypeSpec + nameComponentConstraint
  81. pass
  82. class AttributeDescription(LDAPString):
  83. # AttributeDescription ::= LDAPString -- Constrained to <attributedescription>
  84. # -- [RFC4512]
  85. # subtypeSpec = LDAPString.subtypeSpec + attributeDescriptionConstraint
  86. pass
  87. class AttributeValue(OctetString):
  88. # AttributeValue ::= OCTET STRING
  89. encoding = 'utf-8'
  90. class AssertionValue(OctetString):
  91. # AssertionValue ::= OCTET STRING
  92. encoding = 'utf-8'
  93. class AttributeValueAssertion(Sequence):
  94. # AttributeValueAssertion ::= SEQUENCE {
  95. # attributeDesc AttributeDescription,
  96. # assertionValue AssertionValue }
  97. componentType = NamedTypes(NamedType('attributeDesc', AttributeDescription()),
  98. NamedType('assertionValue', AssertionValue()))
  99. class MatchingRuleId(LDAPString):
  100. # MatchingRuleId ::= LDAPString
  101. pass
  102. class Vals(SetOf):
  103. # vals SET OF value AttributeValue }
  104. componentType = AttributeValue()
  105. class ValsAtLeast1(SetOf):
  106. # vals SET OF value AttributeValue }
  107. componentType = AttributeValue()
  108. subtypeSpec = SetOf.subtypeSpec + size1ToMaxConstraint
  109. class PartialAttribute(Sequence):
  110. # PartialAttribute ::= SEQUENCE {
  111. # type AttributeDescription,
  112. # vals SET OF value AttributeValue }
  113. componentType = NamedTypes(NamedType('type', AttributeDescription()),
  114. NamedType('vals', Vals()))
  115. class Attribute(Sequence):
  116. # Attribute ::= PartialAttribute(WITH COMPONENTS {
  117. # ...,
  118. # vals (SIZE(1..MAX))})
  119. componentType = NamedTypes(NamedType('type', AttributeDescription()),
  120. # NamedType('vals', ValsAtLeast1()))
  121. NamedType('vals', Vals())) # changed from ValsAtLeast1() to allow empty member values in groups - this should not be as per rfc4511 4.1.7, but openldap accept it
  122. class AttributeList(SequenceOf):
  123. # AttributeList ::= SEQUENCE OF attribute Attribute
  124. componentType = Attribute()
  125. class Simple(OctetString):
  126. # simple [0] OCTET STRING,
  127. tagSet = OctetString.tagSet.tagImplicitly(Tag(tagClassContext, tagFormatSimple, 0))
  128. encoding = 'utf-8'
  129. class Credentials(OctetString):
  130. # credentials OCTET STRING
  131. encoding = 'utf-8'
  132. class SaslCredentials(Sequence):
  133. # SaslCredentials ::= SEQUENCE {
  134. # mechanism LDAPString,
  135. # credentials OCTET STRING OPTIONAL }
  136. tagSet = Sequence.tagSet.tagImplicitly(Tag(tagClassContext, tagFormatConstructed, 3))
  137. componentType = NamedTypes(NamedType('mechanism', LDAPString()),
  138. OptionalNamedType('credentials', Credentials()))
  139. # not in RFC4511 but used by Microsoft to embed the NTLM protocol in the BindRequest (Sicily Protocol)
  140. class SicilyPackageDiscovery(OctetString):
  141. # sicilyPackageDiscovery [9] OCTET STRING,
  142. tagSet = OctetString.tagSet.tagImplicitly(Tag(tagClassContext, tagFormatSimple, 9))
  143. encoding = 'utf-8'
  144. # not in RFC4511 but used by Microsoft to embed the NTLM protocol in the BindRequest (Sicily Protocol)
  145. class SicilyNegotiate(OctetString):
  146. # sicilyNegotiate [10] OCTET STRING,
  147. tagSet = OctetString.tagSet.tagImplicitly(Tag(tagClassContext, tagFormatSimple, 10))
  148. encoding = 'utf-8'
  149. # not in RFC4511 but used by Microsoft to embed the NTLM protocol in the BindRequest (Sicily Protocol)
  150. class SicilyResponse(OctetString):
  151. # sicilyResponse [11] OCTET STRING,
  152. tagSet = OctetString.tagSet.tagImplicitly(Tag(tagClassContext, tagFormatSimple, 11))
  153. encoding = 'utf-8'
  154. class AuthenticationChoice(Choice):
  155. # AuthenticationChoice ::= CHOICE {
  156. # simple [0] OCTET STRING,
  157. # -- 1 and 2 reserved
  158. # sasl [3] SaslCredentials,
  159. # ... }
  160. # from https://msdn.microsoft.com/en-us/library/cc223498.aspx # legacy NTLM authentication for Windows Active Directory
  161. # sicilyPackageDiscovery [9] OCTET STRING
  162. # sicilyNegotiate [10] OCTET STRING
  163. # sicilyResponse [11] OCTET STRING }
  164. componentType = NamedTypes(NamedType('simple', Simple()),
  165. NamedType('sasl', SaslCredentials()),
  166. NamedType('sicilyPackageDiscovery', SicilyPackageDiscovery()),
  167. NamedType('sicilyNegotiate', SicilyNegotiate()),
  168. NamedType('sicilyResponse', SicilyResponse()),
  169. )
  170. class Version(Integer):
  171. # version INTEGER (1 .. 127),
  172. subtypeSpec = Integer.subtypeSpec + rangeInt1To127Constraint
  173. class ResultCode(Enumerated):
  174. # resultCode ENUMERATED {
  175. # success (0),
  176. # operationsError (1),
  177. # protocolError (2),
  178. # timeLimitExceeded (3),
  179. # sizeLimitExceeded (4),
  180. # compareFalse (5),
  181. # compareTrue (6),
  182. # authMethodNotSupported (7),
  183. # strongerAuthRequired (8),
  184. # -- 9 reserved --
  185. # referral (10),
  186. # adminLimitExceeded (11),
  187. # unavailableCriticalExtension (12),
  188. # confidentialityRequired (13),
  189. # saslBindInProgress (14),
  190. # noSuchAttribute (16),
  191. # undefinedAttributeType (17),
  192. # inappropriateMatching (18),
  193. # constraintViolation (19),
  194. # attributeOrValueExists (20),
  195. # invalidAttributeSyntax (21),
  196. # -- 22-31 unused --
  197. # noSuchObject (32),
  198. # aliasProblem (33),
  199. # invalidDNSyntax (34),
  200. # -- 35 reserved for undefined isLeaf --
  201. # aliasDereferencingProblem (36),
  202. # -- 37-47 unused --
  203. # inappropriateAuthentication (48),
  204. # invalidCredentials (49),
  205. # insufficientAccessRights (50),
  206. # busy (51),
  207. # unavailable (52),
  208. # unwillingToPerform (53),
  209. # loopDetect (54),
  210. # -- 55-63 unused --
  211. # namingViolation (64),
  212. # objectClassViolation (65),
  213. # notAllowedOnNonLeaf (66),
  214. # notAllowedOnRDN (67),
  215. # entryAlreadyExists (68),
  216. # objectClassModsProhibited (69),
  217. # -- 70 reserved for CLDAP --
  218. # affectsMultipleDSAs (71),
  219. # -- 72-79 unused --
  220. # other (80),
  221. # ... }
  222. #
  223. # from IANA ldap-parameters:
  224. # lcupResourcesExhausted 113 IESG [RFC3928]
  225. # lcupSecurityViolation 114 IESG [RFC3928]
  226. # lcupInvalidData 115 IESG [RFC3928]
  227. # lcupUnsupportedScheme 116 IESG [RFC3928]
  228. # lcupReloadRequired 117 IESG [RFC3928]
  229. # canceled 118 IESG [RFC3909]
  230. # noSuchOperation 119 IESG [RFC3909]
  231. # tooLate 120 IESG [RFC3909]
  232. # cannotCancel 121 IESG [RFC3909]
  233. # assertionFailed 122 IESG [RFC4528]
  234. # authorizationDenied 123 WELTMAN [RFC4370]
  235. # e-syncRefreshRequired 4096 [Kurt_Zeilenga] [Jong_Hyuk_Choi] [RFC4533]
  236. namedValues = NamedValues(('success', 0),
  237. ('operationsError', 1),
  238. ('protocolError', 2),
  239. ('timeLimitExceeded', 3),
  240. ('sizeLimitExceeded', 4),
  241. ('compareFalse', 5),
  242. ('compareTrue', 6),
  243. ('authMethodNotSupported', 7),
  244. ('strongerAuthRequired', 8),
  245. ('referral', 10),
  246. ('adminLimitExceeded', 11),
  247. ('unavailableCriticalExtension', 12),
  248. ('confidentialityRequired', 13),
  249. ('saslBindInProgress', 14),
  250. ('noSuchAttribute', 16),
  251. ('undefinedAttributeType', 17),
  252. ('inappropriateMatching', 18),
  253. ('constraintViolation', 19),
  254. ('attributeOrValueExists', 20),
  255. ('invalidAttributeSyntax', 21),
  256. ('noSuchObject', 32),
  257. ('aliasProblem', 33),
  258. ('invalidDNSyntax', 34),
  259. ('aliasDereferencingProblem', 36),
  260. ('inappropriateAuthentication', 48),
  261. ('invalidCredentials', 49),
  262. ('insufficientAccessRights', 50),
  263. ('busy', 51),
  264. ('unavailable', 52),
  265. ('unwillingToPerform', 53),
  266. ('loopDetected', 54),
  267. ('namingViolation', 64),
  268. ('objectClassViolation', 65),
  269. ('notAllowedOnNonLeaf', 66),
  270. ('notAllowedOnRDN', 67),
  271. ('entryAlreadyExists', 68),
  272. ('objectClassModsProhibited', 69),
  273. ('affectMultipleDSAs', 71),
  274. ('other', 80),
  275. ('lcupResourcesExhausted', 113),
  276. ('lcupSecurityViolation', 114),
  277. ('lcupInvalidData', 115),
  278. ('lcupUnsupportedScheme', 116),
  279. ('lcupReloadRequired', 117),
  280. ('canceled', 118),
  281. ('noSuchOperation', 119),
  282. ('tooLate', 120),
  283. ('cannotCancel', 121),
  284. ('assertionFailed', 122),
  285. ('authorizationDenied', 123),
  286. ('e-syncRefreshRequired', 4096))
  287. subTypeSpec = Enumerated.subtypeSpec + responseValueConstraint
  288. class URI(LDAPString):
  289. # URI ::= LDAPString -- limited to characters permitted in
  290. # -- URIs
  291. # subtypeSpec = LDAPString.subTypeSpec + uriConstrain
  292. pass
  293. class Referral(SequenceOf):
  294. # Referral ::= SEQUENCE SIZE (1..MAX) OF uri URI
  295. tagSet = SequenceOf.tagSet.tagImplicitly(Tag(tagClassContext, tagFormatConstructed, 3))
  296. componentType = URI()
  297. class ServerSaslCreds(OctetString):
  298. # serverSaslCreds [7] OCTET STRING OPTIONAL
  299. tagSet = OctetString.tagSet.tagImplicitly(Tag(tagClassContext, tagFormatSimple, 7))
  300. encoding = 'utf-8'
  301. class LDAPResult(Sequence):
  302. # LDAPResult ::= SEQUENCE {
  303. # resultCode ENUMERATED {
  304. # success (0),
  305. # operationsError (1),
  306. # protocolError (2),
  307. # timeLimitExceeded (3),
  308. # sizeLimitExceeded (4),
  309. # compareFalse (5),
  310. # compareTrue (6),
  311. # authMethodNotSupported (7),
  312. # strongerAuthRequired (8),
  313. # -- 9 reserved --
  314. # referral (10),
  315. # adminLimitExceeded (11),
  316. # unavailableCriticalExtension (12),
  317. # confidentialityRequired (13),
  318. # saslBindInProgress (14),
  319. # noSuchAttribute (16),
  320. # undefinedAttributeType (17),
  321. # inappropriateMatching (18),
  322. # constraintViolation (19),
  323. # attributeOrValueExists (20),
  324. # invalidAttributeSyntax (21),
  325. # -- 22-31 unused --
  326. # noSuchObject (32),
  327. # aliasProblem (33),
  328. # invalidDNSyntax (34),
  329. # -- 35 reserved for undefined isLeaf --
  330. # aliasDereferencingProblem (36),
  331. # -- 37-47 unused --
  332. # inappropriateAuthentication (48),
  333. # invalidCredentials (49),
  334. # insufficientAccessRights (50),
  335. # busy (51),
  336. # unavailable (52),
  337. # unwillingToPerform (53),
  338. # loopDetect (54),
  339. # -- 55-63 unused --
  340. # namingViolation (64),
  341. # objectClassViolation (65),
  342. # notAllowedOnNonLeaf (66),
  343. # notAllowedOnRDN (67),
  344. # entryAlreadyExists (68),
  345. # objectClassModsProhibited (69),
  346. # -- 70 reserved for CLDAP --
  347. # affectsMultipleDSAs (71),
  348. # -- 72-79 unused --
  349. # other (80),
  350. # ... },
  351. # matchedDN LDAPDN,
  352. # diagnosticMessage LDAPString,
  353. # referral [3] Referral OPTIONAL }
  354. componentType = NamedTypes(NamedType('resultCode', ResultCode()),
  355. NamedType('matchedDN', LDAPDN()),
  356. NamedType('diagnosticMessage', LDAPString()),
  357. OptionalNamedType('referral', Referral()))
  358. class Criticality(Boolean):
  359. # criticality BOOLEAN DEFAULT FALSE
  360. defaultValue = False
  361. class ControlValue(OctetString):
  362. # controlValue OCTET STRING
  363. encoding = 'utf-8'
  364. class Control(Sequence):
  365. # Control ::= SEQUENCE {
  366. # controlType LDAPOID,
  367. # criticality BOOLEAN DEFAULT FALSE,
  368. # controlValue OCTET STRING OPTIONAL }
  369. componentType = NamedTypes(NamedType('controlType', LDAPOID()),
  370. DefaultedNamedType('criticality', Criticality()),
  371. OptionalNamedType('controlValue', ControlValue()))
  372. class Controls(SequenceOf):
  373. # Controls ::= SEQUENCE OF control Control
  374. tagSet = SequenceOf.tagSet.tagImplicitly(Tag(tagClassContext, tagFormatConstructed, 0))
  375. componentType = Control()
  376. class Scope(Enumerated):
  377. # scope ENUMERATED {
  378. # baseObject (0),
  379. # singleLevel (1),
  380. # wholeSubtree (2),
  381. namedValues = NamedValues(('baseObject', 0),
  382. ('singleLevel', 1),
  383. ('wholeSubtree', 2))
  384. class DerefAliases(Enumerated):
  385. # derefAliases ENUMERATED {
  386. # neverDerefAliases (0),
  387. # derefInSearching (1),
  388. # derefFindingBaseObj (2),
  389. # derefAlways (3) },
  390. namedValues = NamedValues(('neverDerefAliases', 0),
  391. ('derefInSearching', 1),
  392. ('derefFindingBaseObj', 2),
  393. ('derefAlways', 3))
  394. class TypesOnly(Boolean):
  395. # typesOnly BOOLEAN
  396. pass
  397. class Selector(LDAPString):
  398. # -- The LDAPString is constrained to
  399. # -- <attributeSelector> in Section 4.5.1.8
  400. # subtypeSpec = LDAPString.subtypeSpec + attributeSelectorConstraint
  401. pass
  402. class AttributeSelection(SequenceOf):
  403. # AttributeSelection ::= SEQUENCE OF selector LDAPString
  404. # -- The LDAPString is constrained to
  405. # -- <attributeSelector> in Section 4.5.1.8
  406. componentType = Selector()
  407. class MatchingRule(MatchingRuleId):
  408. # matchingRule [1] MatchingRuleId
  409. tagSet = MatchingRuleId.tagSet.tagImplicitly(Tag(tagClassContext, tagFormatSimple, 1))
  410. class Type(AttributeDescription):
  411. # type [2] AttributeDescription
  412. tagSet = AttributeDescription.tagSet.tagImplicitly(Tag(tagClassContext, tagFormatSimple, 2))
  413. class MatchValue(AssertionValue):
  414. # matchValue [3] AssertionValue,
  415. tagSet = AssertionValue.tagSet.tagImplicitly(Tag(tagClassContext, tagFormatSimple, 3))
  416. class DnAttributes(Boolean):
  417. # dnAttributes [4] BOOLEAN DEFAULT FALSE }
  418. tagSet = Boolean.tagSet.tagImplicitly(Tag(tagClassContext, tagFormatSimple, 4))
  419. defaultValue = Boolean(False)
  420. class MatchingRuleAssertion(Sequence):
  421. # MatchingRuleAssertion ::= SEQUENCE {
  422. # matchingRule [1] MatchingRuleId OPTIONAL,
  423. # type [2] AttributeDescription OPTIONAL,
  424. # matchValue [3] AssertionValue,
  425. # dnAttributes [4] BOOLEAN DEFAULT FALSE }
  426. componentType = NamedTypes(OptionalNamedType('matchingRule', MatchingRule()),
  427. OptionalNamedType('type', Type()),
  428. NamedType('matchValue', MatchValue()),
  429. DefaultedNamedType('dnAttributes', DnAttributes()))
  430. class Initial(AssertionValue):
  431. # initial [0] AssertionValue, -- can occur at most once
  432. tagSet = AssertionValue.tagSet.tagImplicitly(Tag(tagClassContext, tagFormatSimple, 0))
  433. class Any(AssertionValue):
  434. # any [1] AssertionValue,
  435. tagSet = AssertionValue.tagSet.tagImplicitly(Tag(tagClassContext, tagFormatSimple, 1))
  436. class Final(AssertionValue):
  437. # final [1] AssertionValue, -- can occur at most once
  438. tagSet = AssertionValue.tagSet.tagImplicitly(Tag(tagClassContext, tagFormatSimple, 2))
  439. class Substring(Choice):
  440. # substring CHOICE {
  441. # initial [0] AssertionValue, -- can occur at most once
  442. # any [1] AssertionValue,
  443. # final [2] AssertionValue } -- can occur at most once
  444. # }
  445. componentType = NamedTypes(NamedType('initial', Initial()),
  446. NamedType('any', Any()),
  447. NamedType('final', Final()))
  448. class Substrings(SequenceOf):
  449. # substrings SEQUENCE SIZE (1..MAX) OF substring CHOICE {
  450. # ...
  451. # }
  452. subtypeSpec = SequenceOf.subtypeSpec + size1ToMaxConstraint
  453. componentType = Substring()
  454. class SubstringFilter(Sequence):
  455. # SubstringFilter ::= SEQUENCE {
  456. # type AttributeDescription,
  457. # substrings SEQUENCE SIZE (1..MAX) OF substring CHOICE {
  458. # initial [0] AssertionValue, -- can occur at most once
  459. # any [1] AssertionValue,
  460. # final [2] AssertionValue } -- can occur at most once
  461. # }
  462. tagSet = Sequence.tagSet.tagImplicitly(Tag(tagClassContext, tagFormatConstructed, 4))
  463. componentType = NamedTypes(NamedType('type', AttributeDescription()),
  464. NamedType('substrings', Substrings()))
  465. class And(SetOf):
  466. # and [0] SET SIZE (1..MAX) OF filter Filter
  467. tagSet = SetOf.tagSet.tagImplicitly(Tag(tagClassContext, tagFormatConstructed, 0))
  468. subtypeSpec = SetOf.subtypeSpec + size1ToMaxConstraint
  469. class Or(SetOf):
  470. # or [1] SET SIZE (1..MAX) OF filter Filter
  471. tagSet = SetOf.tagSet.tagImplicitly(Tag(tagClassContext, tagFormatConstructed, 1))
  472. subtypeSpec = SetOf.subtypeSpec + size1ToMaxConstraint
  473. class Not(Choice):
  474. # not [2] Filter
  475. pass # defined after Filter definition to allow recursion
  476. class EqualityMatch(AttributeValueAssertion):
  477. # equalityMatch [3] AttributeValueAssertion
  478. tagSet = AttributeValueAssertion.tagSet.tagImplicitly(Tag(tagClassContext, tagFormatConstructed, 3))
  479. class GreaterOrEqual(AttributeValueAssertion):
  480. # greaterOrEqual [5] AttributeValueAssertion
  481. tagSet = AttributeValueAssertion.tagSet.tagImplicitly(Tag(tagClassContext, tagFormatConstructed, 5))
  482. class LessOrEqual(AttributeValueAssertion):
  483. # lessOrEqual [6] AttributeValueAssertion
  484. tagSet = AttributeValueAssertion.tagSet.tagImplicitly(Tag(tagClassContext, tagFormatConstructed, 6))
  485. class Present(AttributeDescription):
  486. # present [7] AttributeDescription
  487. tagSet = AttributeDescription.tagSet.tagImplicitly(Tag(tagClassContext, tagFormatConstructed, 7))
  488. class ApproxMatch(AttributeValueAssertion):
  489. # approxMatch [8] AttributeValueAssertion
  490. tagSet = AttributeValueAssertion.tagSet.tagImplicitly(Tag(tagClassContext, tagFormatConstructed, 8))
  491. class ExtensibleMatch(MatchingRuleAssertion):
  492. # extensibleMatch [9] MatchingRuleAssertion
  493. tagSet = MatchingRuleAssertion.tagSet.tagImplicitly(Tag(tagClassContext, tagFormatConstructed, 9))
  494. class Filter(Choice):
  495. # Filter ::= CHOICE {
  496. # and [0] SET SIZE (1..MAX) OF filter Filter,
  497. # or [1] SET SIZE (1..MAX) OF filter Filter,
  498. # not [2] Filter,
  499. # equalityMatch [3] AttributeValueAssertion,
  500. # substrings [4] SubstringFilter,
  501. # greaterOrEqual [5] AttributeValueAssertion,
  502. # lessOrEqual [6] AttributeValueAssertion,
  503. # present [7] AttributeDescription,
  504. # approxMatch [8] AttributeValueAssertion,
  505. # extensibleMatch [9] MatchingRuleAssertion,
  506. # ... }
  507. componentType = NamedTypes(NamedType('and', And()),
  508. NamedType('or', Or()),
  509. NamedType('notFilter', Not()),
  510. NamedType('equalityMatch', EqualityMatch()),
  511. NamedType('substringFilter', SubstringFilter()),
  512. NamedType('greaterOrEqual', GreaterOrEqual()),
  513. NamedType('lessOrEqual', LessOrEqual()),
  514. NamedType('present', Present()),
  515. NamedType('approxMatch', ApproxMatch()),
  516. NamedType('extensibleMatch', ExtensibleMatch()))
  517. And.componentType = Filter()
  518. Or.componentType = Filter()
  519. Not.componentType = NamedTypes(NamedType('innerNotFilter', Filter()))
  520. Not.tagSet = Filter.tagSet.tagExplicitly(Tag(tagClassContext, tagFormatConstructed, 2)) # as per RFC4511 page 23
  521. class PartialAttributeList(SequenceOf):
  522. # PartialAttributeList ::= SEQUENCE OF
  523. # partialAttribute PartialAttribute
  524. componentType = PartialAttribute()
  525. class Operation(Enumerated):
  526. # operation ENUMERATED {
  527. # add (0),
  528. # delete (1),
  529. # replace (2),
  530. # ... }
  531. namedValues = NamedValues(('add', 0),
  532. ('delete', 1),
  533. ('replace', 2),
  534. ('increment', 3))
  535. class Change(Sequence):
  536. # change SEQUENCE {
  537. # operation ENUMERATED {
  538. # add (0),
  539. # delete (1),
  540. # replace (2),
  541. # ... },
  542. # modification PartialAttribute } }
  543. componentType = NamedTypes(NamedType('operation', Operation()),
  544. NamedType('modification', PartialAttribute()))
  545. class Changes(SequenceOf):
  546. # changes SEQUENCE OF change SEQUENCE
  547. componentType = Change()
  548. class DeleteOldRDN(Boolean):
  549. # deleteoldrdn BOOLEAN
  550. pass
  551. class NewSuperior(LDAPDN):
  552. # newSuperior [0] LDAPDN
  553. tagSet = LDAPDN.tagSet.tagImplicitly(Tag(tagClassContext, tagFormatSimple, 0))
  554. class RequestName(LDAPOID):
  555. # requestName [0] LDAPOID
  556. tagSet = LDAPOID.tagSet.tagImplicitly(Tag(tagClassContext, tagFormatSimple, 0))
  557. class RequestValue(OctetString):
  558. # requestValue [1] OCTET STRING
  559. tagSet = OctetString.tagSet.tagImplicitly(Tag(tagClassContext, tagFormatSimple, 1))
  560. encoding = 'utf-8'
  561. class ResponseName(LDAPOID):
  562. # responseName [10] LDAPOID
  563. tagSet = LDAPOID.tagSet.tagImplicitly(Tag(tagClassContext, tagFormatSimple, 10))
  564. class ResponseValue(OctetString):
  565. # responseValue [11] OCTET STRING
  566. tagSet = OctetString.tagSet.tagImplicitly(Tag(tagClassContext, tagFormatSimple, 11))
  567. encoding = 'utf-8'
  568. class IntermediateResponseName(LDAPOID):
  569. # responseName [0] LDAPOID
  570. tagSet = LDAPOID.tagSet.tagImplicitly(Tag(tagClassContext, tagFormatSimple, 0))
  571. class IntermediateResponseValue(OctetString):
  572. # responseValue [1] OCTET STRING
  573. tagSet = OctetString.tagSet.tagImplicitly(Tag(tagClassContext, tagFormatSimple, 1))
  574. encoding = 'utf-8'
  575. # operations
  576. class BindRequest(Sequence):
  577. # BindRequest ::= [APPLICATION 0] SEQUENCE {
  578. # version INTEGER (1 .. 127),
  579. # name LDAPDN,
  580. # authentication AuthenticationChoice }
  581. tagSet = Sequence.tagSet.tagImplicitly(Tag(tagClassApplication, tagFormatConstructed, 0))
  582. componentType = NamedTypes(NamedType('version', Version()),
  583. NamedType('name', LDAPDN()),
  584. NamedType('authentication', AuthenticationChoice()))
  585. class BindResponse(Sequence):
  586. # BindResponse ::= [APPLICATION 1] SEQUENCE {
  587. # COMPONENTS OF LDAPResult,
  588. # serverSaslCreds [7] OCTET STRING OPTIONAL }
  589. tagSet = Sequence.tagSet.tagImplicitly(Tag(tagClassApplication, tagFormatConstructed, 1))
  590. componentType = NamedTypes(NamedType('resultCode', ResultCode()),
  591. NamedType('matchedDN', LDAPDN()),
  592. NamedType('diagnosticMessage', LDAPString()),
  593. OptionalNamedType('referral', Referral()),
  594. OptionalNamedType('serverSaslCreds', ServerSaslCreds()))
  595. class UnbindRequest(Null):
  596. # UnbindRequest ::= [APPLICATION 2] NULL
  597. tagSet = Null.tagSet.tagImplicitly(Tag(tagClassApplication, tagFormatSimple, 2))
  598. class SearchRequest(Sequence):
  599. # SearchRequest ::= [APPLICATION 3] SEQUENCE {
  600. # baseObject LDAPDN,
  601. # scope ENUMERATED {
  602. # baseObject (0),
  603. # singleLevel (1),
  604. # wholeSubtree (2),
  605. # ... },
  606. # derefAliases ENUMERATED {
  607. # neverDerefAliases (0),
  608. # derefInSearching (1),
  609. # derefFindingBaseObj (2),
  610. # derefAlways (3) },
  611. # sizeLimit INTEGER (0 .. maxInt),
  612. # timeLimit INTEGER (0 .. maxInt),
  613. # typesOnly BOOLEAN,
  614. # filter Filter,
  615. # attributes AttributeSelection }
  616. tagSet = Sequence.tagSet.tagImplicitly(Tag(tagClassApplication, tagFormatConstructed, 3))
  617. componentType = NamedTypes(NamedType('baseObject', LDAPDN()),
  618. NamedType('scope', Scope()),
  619. NamedType('derefAliases', DerefAliases()),
  620. NamedType('sizeLimit', Integer0ToMax()),
  621. NamedType('timeLimit', Integer0ToMax()),
  622. NamedType('typesOnly', TypesOnly()),
  623. NamedType('filter', Filter()),
  624. NamedType('attributes', AttributeSelection()))
  625. class SearchResultReference(SequenceOf):
  626. # SearchResultReference ::= [APPLICATION 19] SEQUENCE
  627. # SIZE (1..MAX) OF uri URI
  628. tagSet = SequenceOf.tagSet.tagImplicitly(Tag(tagClassApplication, tagFormatConstructed, 19))
  629. subtypeSpec = SequenceOf.subtypeSpec + size1ToMaxConstraint
  630. componentType = URI()
  631. class SearchResultEntry(Sequence):
  632. # SearchResultEntry ::= [APPLICATION 4] SEQUENCE {
  633. # objectName LDAPDN,
  634. # attributes PartialAttributeList }
  635. tagSet = Sequence.tagSet.tagImplicitly(Tag(tagClassApplication, tagFormatConstructed, 4))
  636. componentType = NamedTypes(NamedType('object', LDAPDN()),
  637. NamedType('attributes', PartialAttributeList()))
  638. class SearchResultDone(LDAPResult):
  639. # SearchResultDone ::= [APPLICATION 5] LDAPResult
  640. tagSet = LDAPResult.tagSet.tagImplicitly(Tag(tagClassApplication, tagFormatConstructed, 5))
  641. class ModifyRequest(Sequence):
  642. # ModifyRequest ::= [APPLICATION 6] SEQUENCE {
  643. # object LDAPDN,
  644. # changes SEQUENCE OF change SEQUENCE {
  645. # operation ENUMERATED {
  646. # add (0),
  647. # delete (1),
  648. # replace (2),
  649. # ... },
  650. # modification PartialAttribute } }
  651. tagSet = Sequence.tagSet.tagImplicitly(Tag(tagClassApplication, tagFormatConstructed, 6))
  652. componentType = NamedTypes(NamedType('object', LDAPDN()),
  653. NamedType('changes', Changes()))
  654. class ModifyResponse(LDAPResult):
  655. # ModifyResponse ::= [APPLICATION 7] LDAPResult
  656. tagSet = LDAPResult.tagSet.tagImplicitly(Tag(tagClassApplication, tagFormatConstructed, 7))
  657. class AddRequest(Sequence):
  658. # AddRequest ::= [APPLICATION 8] SEQUENCE {
  659. # entry LDAPDN,
  660. # attributes AttributeList }
  661. tagSet = Sequence.tagSet.tagImplicitly(Tag(tagClassApplication, tagFormatConstructed, 8))
  662. componentType = NamedTypes(NamedType('entry', LDAPDN()),
  663. NamedType('attributes', AttributeList()))
  664. class AddResponse(LDAPResult):
  665. # AddResponse ::= [APPLICATION 9] LDAPResult
  666. tagSet = LDAPResult.tagSet.tagImplicitly(Tag(tagClassApplication, tagFormatConstructed, 9))
  667. class DelRequest(LDAPDN):
  668. # DelRequest ::= [APPLICATION 10] LDAPDN
  669. tagSet = LDAPDN.tagSet.tagImplicitly(Tag(tagClassApplication, tagFormatSimple, 10))
  670. class DelResponse(LDAPResult):
  671. # DelResponse ::= [APPLICATION 11] LDAPResult
  672. tagSet = LDAPResult.tagSet.tagImplicitly(Tag(tagClassApplication, tagFormatConstructed, 11))
  673. class ModifyDNRequest(Sequence):
  674. # ModifyDNRequest ::= [APPLICATION 12] SEQUENCE {
  675. # entry LDAPDN,
  676. # newrdn RelativeLDAPDN,
  677. # deleteoldrdn BOOLEAN,
  678. # newSuperior [0] LDAPDN OPTIONAL }
  679. tagSet = Sequence.tagSet.tagImplicitly(Tag(tagClassApplication, tagFormatConstructed, 12))
  680. componentType = NamedTypes(NamedType('entry', LDAPDN()),
  681. NamedType('newrdn', RelativeLDAPDN()),
  682. NamedType('deleteoldrdn', DeleteOldRDN()),
  683. OptionalNamedType('newSuperior', NewSuperior()))
  684. class ModifyDNResponse(LDAPResult):
  685. # ModifyDNResponse ::= [APPLICATION 13] LDAPResult
  686. tagSet = LDAPResult.tagSet.tagImplicitly(Tag(tagClassApplication, tagFormatConstructed, 13))
  687. class CompareRequest(Sequence):
  688. # CompareRequest ::= [APPLICATION 14] SEQUENCE {
  689. # entry LDAPDN,
  690. # ava AttributeValueAssertion }
  691. tagSet = Sequence.tagSet.tagImplicitly(Tag(tagClassApplication, tagFormatConstructed, 14))
  692. componentType = NamedTypes(NamedType('entry', LDAPDN()),
  693. NamedType('ava', AttributeValueAssertion()))
  694. class CompareResponse(LDAPResult):
  695. # CompareResponse ::= [APPLICATION 15] LDAPResult
  696. tagSet = LDAPResult.tagSet.tagImplicitly(Tag(tagClassApplication, tagFormatConstructed, 15))
  697. class AbandonRequest(MessageID):
  698. # AbandonRequest ::= [APPLICATION 16] MessageID
  699. tagSet = MessageID.tagSet.tagImplicitly(Tag(tagClassApplication, tagFormatSimple, 16))
  700. class ExtendedRequest(Sequence):
  701. # ExtendedRequest ::= [APPLICATION 23] SEQUENCE {
  702. # requestName [0] LDAPOID,
  703. # requestValue [1] OCTET STRING OPTIONAL }
  704. tagSet = Sequence.tagSet.tagImplicitly(Tag(tagClassApplication, tagFormatConstructed, 23))
  705. componentType = NamedTypes(NamedType('requestName', RequestName()),
  706. OptionalNamedType('requestValue', RequestValue()))
  707. class ExtendedResponse(Sequence):
  708. # ExtendedResponse ::= [APPLICATION 24] SEQUENCE {
  709. # COMPONENTS OF LDAPResult,
  710. # responseName [10] LDAPOID OPTIONAL,
  711. # responseValue [11] OCTET STRING OPTIONAL }
  712. tagSet = Sequence.tagSet.tagImplicitly(Tag(tagClassApplication, tagFormatConstructed, 24))
  713. componentType = NamedTypes(NamedType('resultCode', ResultCode()),
  714. NamedType('matchedDN', LDAPDN()),
  715. NamedType('diagnosticMessage', LDAPString()),
  716. OptionalNamedType('referral', Referral()),
  717. OptionalNamedType('responseName', ResponseName()),
  718. OptionalNamedType('responseValue', ResponseValue()))
  719. class IntermediateResponse(Sequence):
  720. # IntermediateResponse ::= [APPLICATION 25] SEQUENCE {
  721. # responseName [0] LDAPOID OPTIONAL,
  722. # responseValue [1] OCTET STRING OPTIONAL }
  723. tagSet = Sequence.tagSet.tagImplicitly(Tag(tagClassApplication, tagFormatConstructed, 25))
  724. componentType = NamedTypes(OptionalNamedType('responseName', IntermediateResponseName()),
  725. OptionalNamedType('responseValue', IntermediateResponseValue()))
  726. class ProtocolOp(Choice):
  727. # protocolOp CHOICE {
  728. # bindRequest BindRequest,
  729. # bindResponse BindResponse,
  730. # unbindRequest UnbindRequest,
  731. # searchRequest SearchRequest,
  732. # searchResEntry SearchResultEntry,
  733. # searchResDone SearchResultDone,
  734. # searchResRef SearchResultReference,
  735. # modifyRequest ModifyRequest,
  736. # modifyResponse ModifyResponse,
  737. # addRequest AddRequest,
  738. # addResponse AddResponse,
  739. # delRequest DelRequest,
  740. # delResponse DelResponse,
  741. # modDNRequest ModifyDNRequest,
  742. # modDNResponse ModifyDNResponse,
  743. # compareRequest CompareRequest,
  744. # compareResponse CompareResponse,
  745. # abandonRequest AbandonRequest,
  746. # extendedReq ExtendedRequest,
  747. # extendedResp ExtendedResponse,
  748. # ...,
  749. # intermediateResponse IntermediateResponse }
  750. componentType = NamedTypes(NamedType('bindRequest', BindRequest()),
  751. NamedType('bindResponse', BindResponse()),
  752. NamedType('unbindRequest', UnbindRequest()),
  753. NamedType('searchRequest', SearchRequest()),
  754. NamedType('searchResEntry', SearchResultEntry()),
  755. NamedType('searchResDone', SearchResultDone()),
  756. NamedType('searchResRef', SearchResultReference()),
  757. NamedType('modifyRequest', ModifyRequest()),
  758. NamedType('modifyResponse', ModifyResponse()),
  759. NamedType('addRequest', AddRequest()),
  760. NamedType('addResponse', AddResponse()),
  761. NamedType('delRequest', DelRequest()),
  762. NamedType('delResponse', DelResponse()),
  763. NamedType('modDNRequest', ModifyDNRequest()),
  764. NamedType('modDNResponse', ModifyDNResponse()),
  765. NamedType('compareRequest', CompareRequest()),
  766. NamedType('compareResponse', CompareResponse()),
  767. NamedType('abandonRequest', AbandonRequest()),
  768. NamedType('extendedReq', ExtendedRequest()),
  769. NamedType('extendedResp', ExtendedResponse()),
  770. NamedType('intermediateResponse', IntermediateResponse()))
  771. class LDAPMessage(Sequence):
  772. # LDAPMessage ::= SEQUENCE {
  773. # messageID MessageID,
  774. # protocolOp CHOICE {
  775. # bindRequest BindRequest,
  776. # bindResponse BindResponse,
  777. # unbindRequest UnbindRequest,
  778. # searchRequest SearchRequest,
  779. # searchResEntry SearchResultEntry,
  780. # searchResDone SearchResultDone,
  781. # searchResRef SearchResultReference,
  782. # modifyRequest ModifyRequest,
  783. # modifyResponse ModifyResponse,
  784. # addRequest AddRequest,
  785. # addResponse AddResponse,
  786. # delRequest DelRequest,
  787. # delResponse DelResponse,
  788. # modDNRequest ModifyDNRequest,
  789. # modDNResponse ModifyDNResponse,
  790. # compareRequest CompareRequest,
  791. # compareResponse CompareResponse,
  792. # abandonRequest AbandonRequest,
  793. # extendedReq ExtendedRequest,
  794. # extendedResp ExtendedResponse,
  795. # ...,
  796. # intermediateResponse IntermediateResponse },
  797. # controls [0] Controls OPTIONAL }
  798. componentType = NamedTypes(NamedType('messageID', MessageID()),
  799. NamedType('protocolOp', ProtocolOp()),
  800. OptionalNamedType('controls', Controls()))