rstyx 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/rstyx/keyring.rb CHANGED
@@ -1,33 +1,29 @@
1
1
  #!/usr/bin/ruby
2
2
  #
3
- # Copyright (C) 2005-2007 Rafael Sevilla
4
- # This file is part of RStyx
3
+ # Author:: Rafael R. Sevilla (mailto:dido@imperium.ph)
4
+ # Copyright:: Copyright (c) 2005-2007 Rafael R. Sevilla
5
+ # Homepage:: http://rstyx.rubyforge.org/
6
+ # License:: GNU Lesser General Public License / Ruby License
7
+ #
8
+ # $Id: keyring.rb 282 2007-09-19 07:26:50Z dido $
5
9
  #
6
- # RStyx is free software; you can redistribute it and/or modify
7
- # it under the terms of the GNU Lesser General Public License as
8
- # published by the Free Software Foundation; either version 2.1
9
- # of the License, or (at your option) any later version.
10
+ #----------------------------------------------------------------------------
10
11
  #
11
- # RStyx is distributed in the hope that it will be useful, but
12
- # WITHOUT ANY WARRANTY; without even the implied warranty of
13
- # MERCHANTIBILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- # GNU Lesser General Public License for more details.
12
+ # Copyright (C) 2005-2007 Rafael Sevilla
13
+ # This file is part of RStyx
15
14
  #
16
- # You should have received a copy of the GNU Lesser General Public
17
- # License along with RStyx; if not, write to the Free Software
18
- # Foundation, Inc., 51 Franklin St., Fifth Floor, Boston, MA
19
- # 02110-1301 USA.
15
+ # This program is free software; you can redistribute it and/or modify
16
+ # it under the terms of either 1) the GNU Lesser General Public License
17
+ # as published by the Free Software Foundation; either version 3 of the
18
+ # License, or (at your option) any later version; or 2) Ruby's license.
20
19
  #
20
+ # See the file COPYING for complete licensing information
21
21
  #
22
- # Author:: Rafael R. Sevilla (mailto:dido@imperium.ph)
23
- # Copyright:: Copyright (c) 2005-2007 Rafael R. Sevilla
24
- # License:: GNU Lesser General Public License
22
+ #----------------------------------------------------------------------------
25
23
  #
26
24
  # This is an implementation of the Inferno authentication protocol
27
25
  # (keyring). Adapted from the styx-n-9p Java code.
28
26
  #
29
- # $Id: keyring.rb 259 2007-09-18 04:42:01Z dido $
30
- #
31
27
  require 'openssl'
32
28
  require 'rstyx/errors'
33
29
  require 'digest/sha1'
@@ -501,10 +497,10 @@ EOS
501
497
  hispkbuf = getmsg(fd)
502
498
  hispk = InfPublicKey.from_s(hispkbuf)
503
499
  unless verify(info.spk, hiscert, hispkbuf)
504
- raise LocalAuthErr("pk doesn't match certificate")
500
+ raise LocalAuthErr.new("pk doesn't match certificate")
505
501
  end
506
502
  if hiscert.exp != 0 && (Time.at(hiscert.exp) <= Time.now)
507
- raise LocalAuthErr("certificate expired")
503
+ raise LocalAuthErr.new("certificate expired")
508
504
  end
509
505
 
510
506
  # 6. Send a certificate to the peer with alpha**r0 mod p and
@@ -538,7 +534,7 @@ EOS
538
534
  # 9. Send a protocol message containing OK back to the client.
539
535
  sendmsg(fd, "OK")
540
536
  rescue IOError => e
541
- raise LocalAuthErr.new("I/O error: #{e.message} at #{e.backtrace}")
537
+ raise LocalAuthErr.new("I/O error: #{e.message}")
542
538
  rescue InvalidCertificateException => e
543
539
  senderrmsg(fd, "remote: #{e.message}")
544
540
  raise e
@@ -561,7 +557,7 @@ EOS
561
557
  until /OK/ =~ getmsg(fd)
562
558
  end
563
559
  rescue Exception => e
564
- raise AuthenticationException.new("i/o error: #{e.message} #{e.backtrace.join("\n")}")
560
+ raise AuthenticationException.new("i/o error: #{e.message}")
565
561
  end
566
562
  return([peerauth, secret])
567
563
  end
@@ -668,5 +664,65 @@ EOS
668
664
  return(Certificate.new("rsa", "sha1", sk.owner, exp, sig))
669
665
  end
670
666
 
667
+ ##
668
+ # A connection wrapper, which provides read and write methods
669
+ # just like a socket, given a connection object.
670
+ #
671
+ class FileWrapper
672
+ attr_accessor :data
673
+ ##
674
+ # Create a new FileWrapper, given an EventMachine connection
675
+ # object.
676
+ #
677
+ def initialize(conn)
678
+ @conn = conn
679
+ @data = ""
680
+ @datalock = Mutex.new
681
+ @dcondvar = ConditionVariable.new
682
+ end
683
+
684
+ ##
685
+ # Write data to the connection
686
+ #
687
+ def write(data)
688
+ @conn.send_data(data)
689
+ end
690
+
691
+ ##
692
+ # Read data from the connection
693
+ #
694
+ def read(length)
695
+ @datalock.synchronize do
696
+ while @data.length < length
697
+ @dcondvar.wait(@datalock)
698
+ end
699
+ retval, rest = @data.unpack("a#{length}a*")
700
+ @data = rest
701
+ return(retval)
702
+ end
703
+ end
704
+
705
+ ##
706
+ # Add data received from the connection here
707
+ #
708
+ def <<(str)
709
+ @datalock.synchronize do
710
+ @data << str
711
+ @dcondvar.signal
712
+ end
713
+ end
714
+
715
+ ##
716
+ # Print data to the connection
717
+ #
718
+ def printf(str, *args)
719
+ str = sprintf(str, *args)
720
+ write(str)
721
+ end
722
+ end
723
+
724
+
725
+
671
726
  end
727
+
672
728
  end
@@ -1,30 +1,27 @@
1
1
  #!/usr/bin/ruby
2
2
  #
3
- # Copyright (C) 2005,2006 Rafael Sevilla
4
- # This file is part of RStyx
3
+ # Author:: Rafael R. Sevilla (mailto:dido@imperium.ph)
4
+ # Copyright:: Copyright (c) 2005-2007 Rafael R. Sevilla
5
+ # Homepage:: http://rstyx.rubyforge.org/
6
+ # License:: GNU Lesser General Public License / Ruby License
5
7
  #
6
- # RStyx is free software; you can redistribute it and/or modify
7
- # it under the terms of the GNU Lesser General Public License as
8
- # published by the Free Software Foundation; either version 2.1
9
- # of the License, or (at your option) any later version.
8
+ # $Id: messages.rb 283 2007-09-19 07:28:28Z dido $
10
9
  #
11
- # RStyx is distributed in the hope that it will be useful, but
12
- # WITHOUT ANY WARRANTY; without even the implied warranty of
13
- # MERCHANTIBILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- # GNU Lesser General Public License for more details.
10
+ #----------------------------------------------------------------------------
15
11
  #
16
- # You should have received a copy of the GNU Lesser General Public
17
- # License along with RStyx; if not, write to the Free Software
18
- # Foundation, Inc., 51 Franklin St., Fifth Floor, Boston, MA
19
- # 02110-1301 USA.
12
+ # Copyright (C) 2005-2007 Rafael Sevilla
13
+ # This file is part of RStyx
20
14
  #
21
- # Styx Message classes and utility functions
15
+ # This program is free software; you can redistribute it and/or modify
16
+ # it under the terms of either 1) the GNU Lesser General Public License
17
+ # as published by the Free Software Foundation; either version 3 of the
18
+ # License, or (at your option) any later version; or 2) Ruby's license.
22
19
  #
23
- # Author:: Rafael R. Sevilla (mailto:dido@imperium.ph)
24
- # Copyright:: Copyright (c) 2005,2006 Rafael R. Sevilla
25
- # License:: GNU Lesser General Public License
20
+ # See the file COPYING for complete licensing information
21
+ #
22
+ #----------------------------------------------------------------------------
26
23
  #
27
- # $Id: messages.rb 242 2007-09-13 08:05:57Z dido $
24
+ # Styx Message classes and utility functions
28
25
  #
29
26
 
30
27
  require 'rstyx/errors'