cyberplat_pki 2.0.0 → 2.0.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.
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |gem|
6
6
  gem.name = "cyberplat_pki"
7
- gem.version = "2.0.0"
7
+ gem.version = "2.0.1"
8
8
  gem.authors = ["Peter Zotov"]
9
9
  gem.email = ["whitequark@whitequark.org"]
10
10
  gem.description = %q{CyberplatPKI is a library for signing Cyberplat requests.}
@@ -15,6 +15,7 @@ Gem::Specification.new do |gem|
15
15
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
16
16
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
17
17
  gem.require_paths = ["lib"]
18
+ gem.extensions = ["ext/mock_the_clock/extconf.rb"]
18
19
 
19
20
  gem.add_development_dependency "rspec"
20
21
  gem.add_dependency 'digest-crc' # For CRC24
@@ -0,0 +1 @@
1
+ *.so
@@ -0,0 +1,2 @@
1
+ mock_the_clock.so: mock_the_clock.c
2
+ gcc -m32 -shared -fPIC -nostdlib -o $@ $<
@@ -0,0 +1 @@
1
+ system "make"
@@ -0,0 +1,53 @@
1
+ #include <string.h>
2
+ #include <assert.h>
3
+ #include <sys/time.h>
4
+ #include <time.h>
5
+ #include <dlfcn.h>
6
+
7
+ /* Remember, remember the fifth of November! 2005-11-05 00:00 UTC. */
8
+ #define TIMESTAMP 1131148800
9
+
10
+ int gettimeofday(struct timeval *tv, struct timezone *tz)
11
+ {
12
+ if(tv) {
13
+ tv->tv_sec = TIMESTAMP;
14
+ tv->tv_usec = 0;
15
+ }
16
+
17
+ if(tz) {
18
+ tz->tz_minuteswest = 0;
19
+ tz->tz_dsttime = 0;
20
+ }
21
+
22
+ return 0;
23
+ }
24
+
25
+ time_t time(time_t *t)
26
+ {
27
+ if(t) {
28
+ *t = TIMESTAMP;
29
+ }
30
+
31
+ return TIMESTAMP;
32
+ }
33
+
34
+ int clock_gettime(clockid_t clk_id, struct timespec *tp) {
35
+ static int (*original)(clockid_t clk_id, struct timespec *tp);
36
+
37
+ if(original == NULL) {
38
+ void *hndl = dlopen("librt.so.1", RTLD_LAZY);
39
+ assert(hndl);
40
+ original = dlsym(hndl, "clock_gettime");
41
+ }
42
+
43
+ switch(clk_id) {
44
+ case CLOCK_REALTIME:
45
+ tp->tv_sec = TIMESTAMP;
46
+ tp->tv_nsec = 0;
47
+
48
+ return 0;
49
+
50
+ default:
51
+ return original(clk_id, tp);
52
+ }
53
+ }
@@ -89,7 +89,10 @@ module CyberplatPKI
89
89
  digest.update signature.metadata
90
90
  signature.hash_msw = digest.digest[0..1]
91
91
 
92
- signature_block = Document.encode64 Packet.save([ signature ])
92
+ trust = TrustPacket.new
93
+ trust.trust = 0xC7.chr
94
+
95
+ signature_block = Packet.save([ signature, trust ])
93
96
 
94
97
  doc = Document.new
95
98
  doc.engine = 1
@@ -98,7 +101,7 @@ module CyberplatPKI
98
101
  doc.ca = KeyId.new '', 0
99
102
  doc.data_length = data.length
100
103
  doc.body = data
101
- doc.signature = signature_block
104
+ doc.signature = Document.encode64 signature_block
102
105
 
103
106
  text = Document.save [ doc ]
104
107
 
@@ -45,17 +45,15 @@ module CyberplatPKI
45
45
 
46
46
  packet_type = (PACKET_TYPES.key(packet.class) << 2) | 0x80
47
47
 
48
- case data.length
49
- when 0x00..0xFF
48
+ if data.length <= 0xFF && !packet.kind_of?(SignaturePacket) && !packet.kind_of?(KeyPacket)
50
49
  putc packet_type
51
50
  putc data.length
52
-
53
- when 0x0100..0xFFFF
51
+ elsif data.length <= 0xFFFF
54
52
  putc packet_type | 1
55
53
 
56
54
  write [ data.length ].pack("n")
57
55
 
58
- when 0x00010000..0xFFFFFFFF
56
+ else
59
57
  putc packet_type | 2
60
58
 
61
59
  write [ data.length ].pack("N")
data/spec/spec_helper.rb CHANGED
@@ -16,4 +16,15 @@ RSpec.configure do |config|
16
16
  config.order = 'random'
17
17
  end
18
18
 
19
+ require 'time'
20
+
21
+ if Time.now != Time.parse('5th November 2005 00:00 UTC')
22
+ puts "Travelling back in time..."
23
+
24
+ mock_path = File.expand_path('../../ext/mock_the_clock/mock_the_clock.so', __FILE__)
25
+ exec "sh", "-c", "LD_PRELOAD=#{mock_path} #{$0}"
26
+ else
27
+ puts "Time.now: #{Time.now}"
28
+ end
29
+
19
30
  require 'cyberplat_pki'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cyberplat_pki
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-11 00:00:00.000000000 Z
12
+ date: 2012-11-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -63,7 +63,8 @@ description: CyberplatPKI is a library for signing Cyberplat requests.
63
63
  email:
64
64
  - whitequark@whitequark.org
65
65
  executables: []
66
- extensions: []
66
+ extensions:
67
+ - ext/mock_the_clock/extconf.rb
67
68
  extra_rdoc_files: []
68
69
  files:
69
70
  - .gitignore
@@ -74,6 +75,10 @@ files:
74
75
  - README.md
75
76
  - Rakefile
76
77
  - cyberplat_pki.gemspec
78
+ - ext/mock_the_clock/.gitignore
79
+ - ext/mock_the_clock/Makefile
80
+ - ext/mock_the_clock/extconf.rb
81
+ - ext/mock_the_clock/mock_the_clock.c
77
82
  - lib/cyberplat_pki.rb
78
83
  - lib/cyberplat_pki/document.rb
79
84
  - lib/cyberplat_pki/document_io_routines.rb