Advertisement
Guest User

Untitled

a guest
Jun 8th, 2017
584
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.23 KB | None | 0 0
  1. Index: proto/xmpp/uim-protocols-xmpp-client.adb
  2. ===================================================================
  3. --- proto/xmpp/uim-protocols-xmpp-client.adb (revision 388)
  4. +++ proto/xmpp/uim-protocols-xmpp-client.adb (working copy)
  5. @@ -61,6 +61,8 @@
  6.  
  7. with Network.Utils;
  8.  
  9. +with GNUTLS.SASL;
  10. +
  11. package body UIM.Protocols.XMPP.Client is
  12.  
  13. use Ada.Strings.Unbounded;
  14. @@ -74,10 +76,11 @@
  15. use Sax.Readers;
  16. use Unicode.CES;
  17. use Unicode.CES.Utf8;
  18. - use Ada.Strings.Unbounded;
  19.  
  20. use Ada.Exceptions;
  21.  
  22. + use GNUTLS.SASL;
  23. +
  24. use type Ada.Streams.Stream_Element_Offset;
  25.  
  26. XML_String : Ada.Strings.Unbounded.Unbounded_String;
  27. @@ -89,21 +92,6 @@
  28. Host : String := "localhost";
  29. Password : String := "123";
  30.  
  31. - function Hex_To_Oct (Sum : String) return String is
  32. - Result : String (Sum'First .. Sum'Last / 2);
  33. - J : Integer := Sum'First;
  34. -
  35. - begin
  36. - for Idx in Result'Range loop
  37. - Result (Idx)
  38. - := Character'Val (Integer'Value (("16#" & Sum (J .. J + 1) & "#")));
  39. -
  40. - J := J + 2;
  41. - end loop;
  42. -
  43. - return Result;
  44. - end Hex_To_Oct;
  45. -
  46. --------------
  47. -- Create --
  48. --------------
  49. @@ -471,68 +459,6 @@
  50.  
  51. end Parse_Challenge;
  52.  
  53. -
  54. - function Generate_SASL_String (JID_Par : String;
  55. - Pass_Par : String;
  56. - Host_Par : String;
  57. - Nonce_Par : String) -- Generates SASL string
  58. - return String
  59. - is
  60. - CNonce : String := "1a2f0ee81279451956625d2368";
  61. -
  62. - SY : String := Hex_To_Oct (GNAT.MD5.Digest (JID_Par &
  63. - ":" &
  64. - Host_Par &
  65. - ":" &
  66. - Pass_Par));
  67. -
  68. - HA1 : String := GNAT.MD5.Digest (SY & ":"
  69. - & Nonce_Par
  70. - & ":" & CNonce);
  71. - HA2 : String := GNAT.MD5.Digest ("AUTHENTICATE:xmpp/" & Host_Par);
  72. - Z : String := GNAT.MD5.Digest (HA1 & ":"
  73. - & Nonce_Par
  74. - & ":00000001:"
  75. - & CNonce & ":auth:"
  76. - & HA2);
  77. -
  78. - Realm_Reply : String
  79. - := "username="""
  80. - & JID_Par
  81. - & """,realm=""" & Host_Par
  82. - & """,nonce=""" & Nonce_Par
  83. - & """,cnonce=""" & CNonce
  84. - & """,nc=00000001"
  85. - & ",qop=auth,digest-uri=""xmpp/"
  86. - & Host_Par
  87. - & """,response=" & Z
  88. - & ",charset=utf-8";
  89. -
  90. - X : Integer := 4 * (Realm_Reply'Length + 2) / 3;
  91. - Y : Integer := X + 2 * (X / 76);
  92. -
  93. - Realm_Reply_Base_64 : String (Realm_Reply'First .. Y);
  94. - Len : Natural;
  95. -
  96. - begin
  97. - Ada.Text_IO.Put_Line ("SY = " & SY);
  98. - Ada.Text_IO.Put_Line ("HA1 = " & HA1);
  99. - Ada.Text_IO.Put_Line ("HA2 = " & HA2);
  100. - Ada.Text_IO.Put_Line ("Z = " & Z);
  101. - Ada.Text_IO.Put_Line ("Realm_Reply = " & Realm_Reply);
  102. - Utils.Base64.Encode
  103. - (Network.Utils.To_Stream_Element_Array (Realm_Reply),
  104. - Realm_Reply_Base_64,
  105. - Len);
  106. - Ada.Text_IO.Put_Line ("Realm_Reply_Base_64 = " & Realm_Reply_Base_64);
  107. -
  108. - return
  109. - "<response xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>"
  110. - & Realm_Reply_Base_64 (Realm_Reply_Base_64'First .. Len)
  111. - & "</response>";
  112. -
  113. - end Generate_SASL_String;
  114. -
  115. -----------------------------
  116. -- Parse_Stream_Features --
  117. -----------------------------
  118. Index: agnutls/gnutls-sasl.adb
  119. ===================================================================
  120. --- agnutls/gnutls-sasl.adb (revision 0)
  121. +++ agnutls/gnutls-sasl.adb (revision 0)
  122. @@ -0,0 +1,140 @@
  123. +------------------------------------------------------------------------------
  124. +-- --
  125. +-- Unix Instant Messenger --
  126. +-- --
  127. +------------------------------------------------------------------------------
  128. +-- --
  129. +-- Copyright © 2009 Ada Labs <coopht@gmail.com> --
  130. +-- --
  131. +-- This is free software; you can redistribute it and/or modify it under --
  132. +-- terms of the GNU General Public License as published by the Free Soft- --
  133. +-- ware Foundation; either version 2, or (at your option) any later ver- --
  134. +-- sion. UIM is distributed in the hope that it will be useful, but WITH- --
  135. +-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
  136. +-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
  137. +-- for more details. You should have received a copy of the GNU General --
  138. +-- Public License distributed with UIM; see file COPYING. If not, write --
  139. +-- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
  140. +-- Boston, MA 02110-1301, USA. --
  141. +-- --
  142. +-- As a special exception, if other files instantiate generics from this --
  143. +-- unit, or you link this unit with other files to produce an executable, --
  144. +-- this unit does not by itself cause the resulting executable to be --
  145. +-- covered by the GNU General Public License. This exception does not --
  146. +-- however invalidate any other reasons why the executable file might be --
  147. +-- covered by the GNU Public License. --
  148. +-- --
  149. +------------------------------------------------------------------------------
  150. +--
  151. +-- <Unit> GNUTLS.SASL
  152. +-- <ImplementationNotes>
  153. +--
  154. +------------------------------------------------------------------------------
  155. +-- $Revision: 386 $ $Author: grubnikov $
  156. +-- $Date: 2010-08-01 01:26:03 +0400 (Вск, 01 Авг 2010) $
  157. +------------------------------------------------------------------------------
  158. +with Ada.Exceptions;
  159. +with Ada.Streams;
  160. +with Ada.Strings.Unbounded;
  161. +with Ada.Text_IO;
  162. +
  163. +with GNAT.MD5;
  164. +with GNAT.Sockets;
  165. +
  166. +with UIM.Utils.Base64;
  167. +
  168. +with Network.Utils;
  169. +
  170. +package body GNUTLS.SASL is
  171. +
  172. + use Ada.Strings.Unbounded;
  173. + use Ada.Text_IO;
  174. + use Ada.Strings.Unbounded;
  175. +
  176. + use Ada.Exceptions;
  177. +
  178. + use type Ada.Streams.Stream_Element_Offset;
  179. +
  180. + ------------------
  181. + -- Hex_To_Oct --
  182. + ------------------
  183. + function Hex_To_Oct (Sum : String) return String is
  184. + Result : String (Sum'First .. Sum'Last / 2);
  185. + J : Integer := Sum'First;
  186. +
  187. + begin
  188. + for Idx in Result'Range loop
  189. + Result (Idx)
  190. + := Character'Val (Integer'Value (("16#" & Sum (J .. J + 1) & "#")));
  191. +
  192. + J := J + 2;
  193. + end loop;
  194. +
  195. + return Result;
  196. + end Hex_To_Oct;
  197. +
  198. + -----------------------------
  199. + -- Generate_SASL_String --
  200. + -----------------------------
  201. + function Generate_SASL_String (JID_Par : String;
  202. + Pass_Par : String;
  203. + Host_Par : String;
  204. + Nonce_Par : String) -- Generates SASL string
  205. + return String
  206. + is
  207. + CNonce : String := "1a2f0ee81279451956625d2368";
  208. +
  209. + SY : String := Hex_To_Oct (GNAT.MD5.Digest (JID_Par &
  210. + ":" &
  211. + Host_Par &
  212. + ":" &
  213. + Pass_Par));
  214. +
  215. + HA1 : String := GNAT.MD5.Digest (SY & ":"
  216. + & Nonce_Par
  217. + & ":" & CNonce);
  218. + HA2 : String := GNAT.MD5.Digest ("AUTHENTICATE:xmpp/" & Host_Par);
  219. + Z : String := GNAT.MD5.Digest (HA1 & ":"
  220. + & Nonce_Par
  221. + & ":00000001:"
  222. + & CNonce & ":auth:"
  223. + & HA2);
  224. +
  225. + Realm_Reply : String
  226. + := "username="""
  227. + & JID_Par
  228. + & """,realm=""" & Host_Par
  229. + & """,nonce=""" & Nonce_Par
  230. + & """,cnonce=""" & CNonce
  231. + & """,nc=00000001"
  232. + & ",qop=auth,digest-uri=""xmpp/"
  233. + & Host_Par
  234. + & """,response=" & Z
  235. + & ",charset=utf-8";
  236. +
  237. + X : Integer := 4 * (Realm_Reply'Length + 2) / 3;
  238. + Y : Integer := X + 2 * (X / 76);
  239. +
  240. + Realm_Reply_Base_64 : String (Realm_Reply'First .. Y);
  241. + Len : Natural;
  242. +
  243. + begin
  244. + Ada.Text_IO.Put_Line ("SY = " & SY);
  245. + Ada.Text_IO.Put_Line ("HA1 = " & HA1);
  246. + Ada.Text_IO.Put_Line ("HA2 = " & HA2);
  247. + Ada.Text_IO.Put_Line ("Z = " & Z);
  248. + Ada.Text_IO.Put_Line ("Realm_Reply = " & Realm_Reply);
  249. + Utils.Base64.Encode
  250. + (Network.Utils.To_Stream_Element_Array (Realm_Reply),
  251. + Realm_Reply_Base_64,
  252. + Len);
  253. + Ada.Text_IO.Put_Line ("Realm_Reply_Base_64 = " & Realm_Reply_Base_64);
  254. +
  255. + return
  256. + "<response xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>"
  257. + & Realm_Reply_Base_64 (Realm_Reply_Base_64'First .. Len)
  258. + & "</response>";
  259. +
  260. + end Generate_SASL_String;
  261. +
  262. +end GNUTLS.SASL;
  263. Index: agnutls/gnutls-sasl.ads
  264. ===================================================================
  265. --- agnutls/gnutls-sasl.ads (revision 0)
  266. +++ agnutls/gnutls-sasl.ads (revision 0)
  267. @@ -0,0 +1,52 @@
  268. +------------------------------------------------------------------------------
  269. +-- --
  270. +-- Unix Instant Messenger --
  271. +-- --
  272. +------------------------------------------------------------------------------
  273. +-- --
  274. +-- Copyright © 2009 Ada Labs <coopht@gmail.com> --
  275. +-- --
  276. +-- This is free software; you can redistribute it and/or modify it under --
  277. +-- terms of the GNU General Public License as published by the Free Soft- --
  278. +-- ware Foundation; either version 2, or (at your option) any later ver- --
  279. +-- sion. UIM is distributed in the hope that it will be useful, but WITH- --
  280. +-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
  281. +-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
  282. +-- for more details. You should have received a copy of the GNU General --
  283. +-- Public License distributed with UIM; see file COPYING. If not, write --
  284. +-- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
  285. +-- Boston, MA 02110-1301, USA. --
  286. +-- --
  287. +-- As a special exception, if other files instantiate generics from this --
  288. +-- unit, or you link this unit with other files to produce an executable, --
  289. +-- this unit does not by itself cause the resulting executable to be --
  290. +-- covered by the GNU General Public License. This exception does not --
  291. +-- however invalidate any other reasons why the executable file might be --
  292. +-- covered by the GNU Public License. --
  293. +-- --
  294. +------------------------------------------------------------------------------
  295. +--
  296. +-- <Unit> UIM.Protocols.XMPP.Client
  297. +-- <ImplementationNotes>
  298. +--
  299. +------------------------------------------------------------------------------
  300. +-- $Revision: 381 $ $Author: coopht $
  301. +-- $Date: 2010-07-18 21:36:24 +0400 (Вск, 18 Июл 2010) $
  302. +------------------------------------------------------------------------------
  303. +with Network;
  304. +
  305. +package GNUTLS.SASL is
  306. +
  307. + ----------------------------
  308. + -- Generate_SASL_String --
  309. + ----------------------------
  310. + function Generate_SASL_String (JID_Par : String;
  311. + Pass_Par : String;
  312. + Host_Par : String;
  313. + Nonce_Par : String) return String;
  314. +
  315. + function Hex_To_Oct (Sum : String) return String;
  316. +
  317. +private
  318. +
  319. +end GNUTLS.SASL;
  320. Index: agnutls/agnutls.gpr
  321. ===================================================================
  322. --- agnutls/agnutls.gpr (revision 387)
  323. +++ agnutls/agnutls.gpr (working copy)
  324. @@ -33,6 +33,8 @@
  325. -- $Revision$ $Author$
  326. -- $Date$
  327. ------------------------------------------------------------------------------
  328. +with "../core/network/network";
  329. +with "../utils/utils";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement