PageRenderTime 433ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/hacs/Libraries/XMPP/agsxmpp/protocol/sasl/Mechanism.cs

https://github.com/bietiekay/hacs
C# | 247 lines | 141 code | 12 blank | 94 comment | 2 complexity | 444e32706f0a45ffe665e309364112f0 MD5 | raw file
  1. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  2. * Copyright (c) 2003-2012 by AG-Software *
  3. * All Rights Reserved. *
  4. * Contact information for AG-Software is available at http://www.ag-software.de *
  5. * *
  6. * Licence: *
  7. * The agsXMPP SDK is released under a dual licence *
  8. * agsXMPP can be used under either of two licences *
  9. * *
  10. * A commercial licence which is probably the most appropriate for commercial *
  11. * corporate use and closed source projects. *
  12. * *
  13. * The GNU Public License (GPL) is probably most appropriate for inclusion in *
  14. * other open source projects. *
  15. * *
  16. * See README.html for details. *
  17. * *
  18. * For general enquiries visit our website at: *
  19. * http://www.ag-software.de *
  20. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  21. using System;
  22. using agsXMPP.Sasl;
  23. using agsXMPP.Xml.Dom;
  24. // <mechanism>DIGEST-MD5</mechanism>
  25. // <mechanism>PLAIN</mechanism>
  26. //MECHANISMS USAGE REFERENCE OWNER
  27. //---------- ----- --------- -----
  28. //KERBEROS_V4 LIMITED [RFC2222] IESG <iesg@ietf.org>
  29. //GSSAPI COMMON [RFC2222] IESG <iesg@ietf.org>
  30. //SKEY OBSOLETE [RFC2444] IESG <iesg@ietf.org>
  31. //EXTERNAL COMMON [RFC2222] IESG <iesg@ietf.org>
  32. //CRAM-MD5 LIMITED [RFC2195] IESG <iesg@ietf.org>
  33. //ANONYMOUS COMMON [RFC2245] IESG <iesg@ietf.org>
  34. //OTP COMMON [RFC2444] IESG <iesg@ietf.org>
  35. //GSS-SPNEGO LIMITED [Leach] Paul Leach <paulle@microsoft.com>
  36. //PLAIN COMMON [RFC2595] IESG <iesg@ietf.org>
  37. //SECURID COMMON [RFC2808] Magnus Nystrom <magnus@rsasecurity.com>
  38. //NTLM LIMITED [Leach] Paul Leach <paulle@microsoft.com>
  39. //NMAS_LOGIN LIMITED [Gayman] Mark G. Gayman <mgayman@novell.com>
  40. //NMAS_AUTHEN LIMITED [Gayman] Mark G. Gayman <mgayman@novell.com>
  41. //DIGEST-MD5 COMMON [RFC2831] IESG <iesg@ietf.org>
  42. //9798-U-RSA-SHA1-ENC COMMON [RFC3163] robert.zuccherato@entrust.com
  43. //9798-M-RSA-SHA1-ENC COMMON [RFC3163] robert.zuccherato@entrust.com
  44. //9798-U-DSA-SHA1 COMMON [RFC3163] robert.zuccherato@entrust.com
  45. //9798-M-DSA-SHA1 COMMON [RFC3163] robert.zuccherato@entrust.com
  46. //9798-U-ECDSA-SHA1 COMMON [RFC3163] robert.zuccherato@entrust.com
  47. //9798-M-ECDSA-SHA1 COMMON [RFC3163] robert.zuccherato@entrust.com
  48. //KERBEROS_V5 COMMON [Josefsson] Simon Josefsson <simon@josefsson.org>
  49. //NMAS-SAMBA-AUTH LIMITED [Brimhall] Vince Brimhall <vbrimhall@novell.com>
  50. namespace agsXMPP.protocol.sasl
  51. {
  52. public enum MechanismType
  53. {
  54. NONE = 0,
  55. KERBEROS_V4,
  56. GSSAPI,
  57. SKEY,
  58. EXTERNAL,
  59. CRAM_MD5,
  60. ANONYMOUS,
  61. OTP,
  62. GSS_SPNEGO,
  63. PLAIN,
  64. SECURID,
  65. NTLM,
  66. NMAS_LOGIN,
  67. NMAS_AUTHEN,
  68. DIGEST_MD5,
  69. ISO_9798_U_RSA_SHA1_ENC,
  70. ISO_9798_M_RSA_SHA1_ENC,
  71. ISO_9798_U_DSA_SHA1,
  72. ISO_9798_M_DSA_SHA1,
  73. ISO_9798_U_ECDSA_SHA1,
  74. ISO_9798_M_ECDSA_SHA1,
  75. KERBEROS_V5,
  76. NMAS_SAMBA_AUTH,
  77. X_GOOGLE_TOKEN,
  78. SCRAM_SHA_1,
  79. X_FACEBOOK_PLATFORM
  80. }
  81. /// <summary>
  82. /// Summary description for Mechanism.
  83. /// </summary>
  84. public class Mechanism : Element
  85. {
  86. public Mechanism()
  87. {
  88. this.TagName = "mechanism";
  89. this.Namespace = Uri.SASL;
  90. }
  91. public Mechanism(MechanismType mechanism) : this()
  92. {
  93. MechanismType = mechanism;
  94. }
  95. /// <summary>
  96. /// SASL mechanis as enum
  97. /// </summary>
  98. public MechanismType MechanismType
  99. {
  100. get
  101. {
  102. return GetMechanismType(this.Value);
  103. }
  104. set
  105. {
  106. this.Value = GetMechanismName(value);
  107. }
  108. }
  109. public static MechanismType GetMechanismType(string mechanism)
  110. {
  111. switch (mechanism)
  112. {
  113. //case "KERBEROS_V4":
  114. // return MechanismType.KERBEROS_V4;
  115. case "GSSAPI":
  116. return MechanismType.GSSAPI;
  117. //case "SKEY":
  118. // return MechanismType.SKEY;
  119. //case "EXTERNAL":
  120. // return MechanismType.EXTERNAL;
  121. //case "CRAM-MD5":
  122. // return MechanismType.CRAM_MD5;
  123. //case "ANONYMOUS":
  124. // return MechanismType.ANONYMOUS;
  125. //case "OTP":
  126. // return MechanismType.OTP;
  127. //case "GSS-SPNEGO":
  128. // return MechanismType.GSS_SPNEGO;
  129. case "PLAIN":
  130. return MechanismType.PLAIN;
  131. //case "SECURID":
  132. // return MechanismType.SECURID;
  133. //case "NTLM":
  134. // return MechanismType.NTLM;
  135. //case "NMAS_LOGIN":
  136. // return MechanismType.NMAS_LOGIN;
  137. //case "NMAS_AUTHEN":
  138. // return MechanismType.NMAS_AUTHEN;
  139. case "DIGEST-MD5":
  140. return MechanismType.DIGEST_MD5;
  141. //case "9798-U-RSA-SHA1-ENC":
  142. // return MechanismType.ISO_9798_U_RSA_SHA1_ENC;
  143. //case "9798-M-RSA-SHA1-ENC":
  144. // return MechanismType.ISO_9798_M_RSA_SHA1_ENC;
  145. //case "9798-U-DSA-SHA1":
  146. // return MechanismType.ISO_9798_U_DSA_SHA1;
  147. //case "9798-M-DSA-SHA1":
  148. // return MechanismType.ISO_9798_M_DSA_SHA1;
  149. //case "9798-U-ECDSA-SHA1":
  150. // return MechanismType.ISO_9798_U_ECDSA_SHA1;
  151. //case "9798-M-ECDSA-SHA1":
  152. // return MechanismType.ISO_9798_M_ECDSA_SHA1;
  153. //case "KERBEROS_V5":
  154. // return MechanismType.KERBEROS_V5;
  155. //case "NMAS-SAMBA-AUTH":
  156. // return MechanismType.NMAS_SAMBA_AUTH;
  157. case "X-GOOGLE-TOKEN":
  158. return MechanismType.X_GOOGLE_TOKEN;
  159. case "SCRAM-SHA-1":
  160. return MechanismType.SCRAM_SHA_1;
  161. case "X-FACEBOOK-PLATFORM":
  162. return MechanismType.X_FACEBOOK_PLATFORM;
  163. default:
  164. return MechanismType.NONE;
  165. }
  166. }
  167. public static string GetMechanismName(MechanismType mechanism)
  168. {
  169. switch (mechanism)
  170. {
  171. case MechanismType.KERBEROS_V4:
  172. return "KERBEROS_V4";
  173. case MechanismType.GSSAPI:
  174. return "GSSAPI";
  175. case MechanismType.SKEY:
  176. return "SKEY";
  177. case MechanismType.EXTERNAL:
  178. return "EXTERNAL";
  179. case MechanismType.CRAM_MD5:
  180. return "CRAM-MD5";
  181. case MechanismType.ANONYMOUS:
  182. return "ANONYMOUS";
  183. case MechanismType.OTP:
  184. return "OTP";
  185. case MechanismType.GSS_SPNEGO:
  186. return "GSS-SPNEGO";
  187. case MechanismType.PLAIN:
  188. return "PLAIN";
  189. case MechanismType.SECURID:
  190. return "SECURID";
  191. case MechanismType.NTLM:
  192. return "NTLM";
  193. case MechanismType.NMAS_LOGIN:
  194. return "NMAS_LOGIN";
  195. case MechanismType.NMAS_AUTHEN:
  196. return "NMAS_AUTHEN";
  197. case MechanismType.DIGEST_MD5:
  198. return "DIGEST-MD5";
  199. case MechanismType.ISO_9798_U_RSA_SHA1_ENC:
  200. return "9798-U-RSA-SHA1-ENC";
  201. case MechanismType.ISO_9798_M_RSA_SHA1_ENC:
  202. return "9798-M-RSA-SHA1-ENC";
  203. case MechanismType.ISO_9798_U_DSA_SHA1:
  204. return "9798-U-DSA-SHA1";
  205. case MechanismType.ISO_9798_M_DSA_SHA1:
  206. return "9798-M-DSA-SHA1";
  207. case MechanismType.ISO_9798_U_ECDSA_SHA1:
  208. return "9798-U-ECDSA-SHA1";
  209. case MechanismType.ISO_9798_M_ECDSA_SHA1:
  210. return "9798-M-ECDSA-SHA1";
  211. case MechanismType.KERBEROS_V5:
  212. return "KERBEROS_V5";
  213. case MechanismType.NMAS_SAMBA_AUTH:
  214. return "NMAS-SAMBA-AUTH";
  215. case MechanismType.X_GOOGLE_TOKEN:
  216. return "X-GOOGLE-TOKEN";
  217. case MechanismType.SCRAM_SHA_1:
  218. return "SCRAM-SHA-1";
  219. case MechanismType.X_FACEBOOK_PLATFORM:
  220. return "X-FACEBOOK-PLATFORM";
  221. default:
  222. return null;
  223. }
  224. }
  225. /// <summary>
  226. /// Gets or sets the kerberos principal.
  227. /// </summary>
  228. /// <value>The kerberos proncipal.</value>
  229. public string KerberosPrincipal
  230. {
  231. get { return GetAttribute("kerb:principal"); }
  232. set { SetAttribute("kerb:principal", value); }
  233. }
  234. }
  235. }