rcs-common 9.6.0

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.
Files changed (116) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +49 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +1 -0
  5. data/Rakefile +27 -0
  6. data/lib/rcs-common.rb +21 -0
  7. data/lib/rcs-common/binary.rb +64 -0
  8. data/lib/rcs-common/cgi.rb +7 -0
  9. data/lib/rcs-common/component.rb +87 -0
  10. data/lib/rcs-common/crypt.rb +71 -0
  11. data/lib/rcs-common/deploy.rb +96 -0
  12. data/lib/rcs-common/diagnosticable.rb +136 -0
  13. data/lib/rcs-common/evidence.rb +261 -0
  14. data/lib/rcs-common/evidence/addressbook.rb +173 -0
  15. data/lib/rcs-common/evidence/application.rb +59 -0
  16. data/lib/rcs-common/evidence/calendar.rb +62 -0
  17. data/lib/rcs-common/evidence/call.rb +185 -0
  18. data/lib/rcs-common/evidence/camera.rb +25 -0
  19. data/lib/rcs-common/evidence/chat.rb +272 -0
  20. data/lib/rcs-common/evidence/clibpoard.rb +58 -0
  21. data/lib/rcs-common/evidence/command.rb +50 -0
  22. data/lib/rcs-common/evidence/common.rb +78 -0
  23. data/lib/rcs-common/evidence/content/camera/001.jpg +0 -0
  24. data/lib/rcs-common/evidence/content/coin/wallet_bit.dat +0 -0
  25. data/lib/rcs-common/evidence/content/coin/wallet_lite.dat +0 -0
  26. data/lib/rcs-common/evidence/content/file/Einstein.docx +0 -0
  27. data/lib/rcs-common/evidence/content/file/arabic.docx +0 -0
  28. data/lib/rcs-common/evidence/content/mouse/001.jpg +0 -0
  29. data/lib/rcs-common/evidence/content/mouse/002.jpg +0 -0
  30. data/lib/rcs-common/evidence/content/mouse/003.jpg +0 -0
  31. data/lib/rcs-common/evidence/content/mouse/004.jpg +0 -0
  32. data/lib/rcs-common/evidence/content/print/001.jpg +0 -0
  33. data/lib/rcs-common/evidence/content/screenshot/001.jpg +0 -0
  34. data/lib/rcs-common/evidence/content/screenshot/002.jpg +0 -0
  35. data/lib/rcs-common/evidence/content/screenshot/003.jpg +0 -0
  36. data/lib/rcs-common/evidence/content/url/001.jpg +0 -0
  37. data/lib/rcs-common/evidence/content/url/002.jpg +0 -0
  38. data/lib/rcs-common/evidence/content/url/003.jpg +0 -0
  39. data/lib/rcs-common/evidence/device.rb +23 -0
  40. data/lib/rcs-common/evidence/download.rb +54 -0
  41. data/lib/rcs-common/evidence/exec.rb +0 -0
  42. data/lib/rcs-common/evidence/file.rb +129 -0
  43. data/lib/rcs-common/evidence/filesystem.rb +71 -0
  44. data/lib/rcs-common/evidence/info.rb +24 -0
  45. data/lib/rcs-common/evidence/keylog.rb +84 -0
  46. data/lib/rcs-common/evidence/mail.rb +237 -0
  47. data/lib/rcs-common/evidence/mic.rb +39 -0
  48. data/lib/rcs-common/evidence/mms.rb +36 -0
  49. data/lib/rcs-common/evidence/money.rb +676 -0
  50. data/lib/rcs-common/evidence/mouse.rb +62 -0
  51. data/lib/rcs-common/evidence/password.rb +60 -0
  52. data/lib/rcs-common/evidence/photo.rb +80 -0
  53. data/lib/rcs-common/evidence/position.rb +303 -0
  54. data/lib/rcs-common/evidence/print.rb +50 -0
  55. data/lib/rcs-common/evidence/screenshot.rb +53 -0
  56. data/lib/rcs-common/evidence/sms.rb +91 -0
  57. data/lib/rcs-common/evidence/url.rb +133 -0
  58. data/lib/rcs-common/fixnum.rb +48 -0
  59. data/lib/rcs-common/gridfs.rb +294 -0
  60. data/lib/rcs-common/heartbeat.rb +96 -0
  61. data/lib/rcs-common/keywords.rb +50 -0
  62. data/lib/rcs-common/mime.rb +65 -0
  63. data/lib/rcs-common/mongoid.rb +19 -0
  64. data/lib/rcs-common/pascalize.rb +62 -0
  65. data/lib/rcs-common/path_utils.rb +67 -0
  66. data/lib/rcs-common/resolver.rb +40 -0
  67. data/lib/rcs-common/rest.rb +17 -0
  68. data/lib/rcs-common/sanitize.rb +42 -0
  69. data/lib/rcs-common/serializer.rb +404 -0
  70. data/lib/rcs-common/signature.rb +141 -0
  71. data/lib/rcs-common/stats.rb +94 -0
  72. data/lib/rcs-common/symbolize.rb +10 -0
  73. data/lib/rcs-common/systemstatus.rb +136 -0
  74. data/lib/rcs-common/temporary.rb +13 -0
  75. data/lib/rcs-common/time.rb +24 -0
  76. data/lib/rcs-common/trace.rb +138 -0
  77. data/lib/rcs-common/trace.yaml +42 -0
  78. data/lib/rcs-common/updater/client.rb +354 -0
  79. data/lib/rcs-common/updater/dsl.rb +178 -0
  80. data/lib/rcs-common/updater/payload.rb +79 -0
  81. data/lib/rcs-common/updater/server.rb +126 -0
  82. data/lib/rcs-common/updater/shared_key.rb +55 -0
  83. data/lib/rcs-common/updater/tmp_dir.rb +13 -0
  84. data/lib/rcs-common/utf16le.rb +83 -0
  85. data/lib/rcs-common/version.rb +5 -0
  86. data/lib/rcs-common/winfirewall.rb +235 -0
  87. data/rcs-common.gemspec +64 -0
  88. data/spec/gridfs_spec.rb +637 -0
  89. data/spec/mongoid.yaml +6 -0
  90. data/spec/signature_spec.rb +105 -0
  91. data/spec/spec_helper.rb +22 -0
  92. data/spec/updater_spec.rb +80 -0
  93. data/tasks/deploy.rake +21 -0
  94. data/tasks/protect.rake +90 -0
  95. data/test/helper.rb +17 -0
  96. data/test/test_binary.rb +107 -0
  97. data/test/test_cgi.rb +14 -0
  98. data/test/test_crypt.rb +125 -0
  99. data/test/test_evidence.rb +52 -0
  100. data/test/test_evidence_manager.rb +119 -0
  101. data/test/test_fixnum.rb +35 -0
  102. data/test/test_keywords.rb +137 -0
  103. data/test/test_mime.rb +49 -0
  104. data/test/test_pascalize.rb +100 -0
  105. data/test/test_path_utils.rb +24 -0
  106. data/test/test_rcs-common.rb +7 -0
  107. data/test/test_sanitize.rb +40 -0
  108. data/test/test_serialization.rb +20 -0
  109. data/test/test_stats.rb +90 -0
  110. data/test/test_symbolize.rb +20 -0
  111. data/test/test_systemstatus.rb +35 -0
  112. data/test/test_time.rb +56 -0
  113. data/test/test_trace.rb +25 -0
  114. data/test/test_utf16le.rb +71 -0
  115. data/test/test_winfirewall.rb +68 -0
  116. metadata +423 -0
@@ -0,0 +1,49 @@
1
+ require 'helper'
2
+
3
+ class TestRcsCommon < Test::Unit::TestCase
4
+
5
+ def test_mime_cod
6
+ mime = RCS::MimeType::get('test.cod')
7
+ expected = 'application/vnd.rim.cod'
8
+ assert_equal expected, mime
9
+ end
10
+
11
+ def test_mime_jad
12
+ mime = RCS::MimeType::get('test.jad')
13
+ expected = 'text/vnd.sun.j2me.app-descriptor'
14
+ assert_equal expected, mime
15
+ end
16
+
17
+ def test_mime_jnlp
18
+ mime = RCS::MimeType::get('test.jnlp')
19
+ expected = 'application/x-java-jnlp-file'
20
+ assert_equal expected, mime
21
+ end
22
+
23
+ def test_mime_cab
24
+ mime = RCS::MimeType::get('test.cab')
25
+ #expected = 'application/vnd.ms-cab-compressed'
26
+ # fucking IE mobile not understanding the real mime type
27
+ expected = 'binary/octet-stream'
28
+ assert_equal expected, mime
29
+ end
30
+
31
+ def test_mime_apk
32
+ mime = RCS::MimeType::get('test.apk')
33
+ expected = 'application/vnd.android.package-archive'
34
+ assert_equal expected, mime
35
+ end
36
+
37
+ def test_mime_exe
38
+ mime = RCS::MimeType::get('test.exe')
39
+ expected = 'application/x-msdos-program'
40
+ assert_equal expected, mime
41
+ end
42
+
43
+ def test_mime_unknown
44
+ mime = RCS::MimeType::get('test.unknown')
45
+ expected = 'binary/octet-stream'
46
+ assert_equal expected, mime
47
+ end
48
+
49
+ end
@@ -0,0 +1,100 @@
1
+ # encoding: utf-8
2
+
3
+ require 'helper'
4
+ require 'securerandom'
5
+
6
+ class PascalizeTest < Test::Unit::TestCase
7
+ def test_pascalize
8
+ source = "ciao"
9
+ # length c i a o null
10
+ dest = "\x0a\x00\x00\x00" + "\x63\x00" + "\x69\x00" + "\x61\x00" + "\x6f\x00" + "\x00\x00"
11
+ pascal = source.pascalize
12
+ assert_equal dest, pascal
13
+ # this is a stream of bytes represented as ASCII
14
+ assert_equal 'ASCII-8BIT', pascal.encoding.to_s
15
+ end
16
+
17
+ def test_unpascalize
18
+ # length c i a o null
19
+ source = "\x0a\x00\x00\x00" + "\x63\x00" + "\x69\x00" + "\x61\x00" + "\x6f\x00" + "\x00\x00"
20
+ dest = "ciao"
21
+ pascal = source.unpascalize
22
+ assert_equal dest, pascal
23
+ assert_equal dest.encoding, pascal.encoding
24
+ end
25
+
26
+ def test_pascalize_unicode
27
+ source = "スパイ"
28
+ # length ス パ イ null
29
+ dest = "\x08\x00\x00\x00" + "\xb9\x30" + "\xd1\x30" + "\xa4\x30" + "\x00\x00"
30
+ pascal = source.pascalize
31
+ # we have to force the comparison in BINARY (alias for ASCII-8BIT) otherwise the
32
+ # assert_equal function will complain about invalid UTF-8 sequence
33
+ assert_equal dest.force_encoding('BINARY'), pascal.force_encoding('BINARY')
34
+ end
35
+
36
+ def test_unpascalize_unicode
37
+ # length ス パ イ null
38
+ source = "\x08\x00\x00\x00" + "\xb9\x30" + "\xd1\x30" + "\xa4\x30" + "\x00\x00"
39
+ dest = "スパイ"
40
+ pascal = source.unpascalize
41
+ assert_equal dest, pascal
42
+ end
43
+
44
+ def test_pascalize_with_zero
45
+ source = "a\x00s"
46
+ # length a null s null
47
+ dest = "\x08\x00\x00\x00" + "\x61\x00" + "\x00\x00" + "\x73\x00" + "\x00\x00"
48
+ assert_equal dest, source.pascalize
49
+ end
50
+
51
+ def test_unpascalize_with_zero
52
+ # length a null s null
53
+ source = "\x08\x00\x00\x00" + "\x61\x00" + "\x00\x00" + "\x73\x00" + "\x00\x00"
54
+ dest = "a\x00s"
55
+ pascal = source.unpascalize
56
+ assert_equal dest, pascal
57
+ assert_equal dest.encoding, pascal.encoding
58
+ end
59
+
60
+ def test_pascalize_null
61
+ source = ""
62
+ # length null
63
+ dest = "\x02\x00\x00\x00" + "\x00\x00"
64
+ assert_equal dest, source.pascalize
65
+ end
66
+
67
+ def test_unpascalize_null
68
+ # length null
69
+ source = "\x02\x00\x00\x00" + "\x00\x00"
70
+ dest = ""
71
+ assert_equal dest, source.unpascalize
72
+ end
73
+
74
+ def test_unpascalize_multi
75
+ multi_source = "\x0a\x00\x00\x00\x41\x00\x4c\x00\x6f\x00\x52\x00\x00\x00" +
76
+ "\x08\x00\x00\x00\xb9\x30\xd1\x30\xa4\x30\x00\x00" +
77
+ "\x1c\x00\x00\x00\x31\x00\x39\x00\x32\x00\x2e\x00\x31\x00\x36\x00\x38\x00\x2e\x00\x31\x00\x2e\x00\x31\x00\x37\x00\x35\x00\x00\x00"
78
+ multi_dest = ["ALoR", "スパイ", "192.168.1.175"]
79
+ assert_equal multi_dest, multi_source.unpascalize_ary
80
+ end
81
+
82
+ def test_unpascalize_multi_and_random
83
+ multi_source = "\x0a\x00\x00\x00c\x00i\x00a\x00o\x00\x00\x00" +
84
+ "\x0a\x00\x00\x00m\x00i\x00a\x00o\x00\x00\x00" +
85
+ "\x08\x00\x00\x00b\x00a\x00o\x00\x00\x00" +
86
+ SecureRandom.random_bytes(32)
87
+
88
+ # the last part of random bytes should be ignored as error
89
+ multi_dest = ["ciao", "miao", "bao"]
90
+ assert_equal multi_dest, multi_source.unpascalize_ary
91
+ end
92
+
93
+ def test_unpascalize_random
94
+ source = SecureRandom.random_bytes(64)
95
+
96
+ assert_nil source.unpascalize
97
+ assert_equal [], source.unpascalize_ary
98
+ end
99
+
100
+ end
@@ -0,0 +1,24 @@
1
+ # encoding: utf-8
2
+
3
+ require 'helper'
4
+ require 'rcs-common/path_utils'
5
+
6
+ class PathutilsTest < Test::Unit::TestCase
7
+
8
+ class IncludePathUtils; include RCS::Common::PathUtils; end
9
+
10
+ def setup
11
+ @subject = IncludePathUtils.new
12
+ end
13
+
14
+ def test_require_release
15
+ assert_raise { @subject.require_release 'folder/file' }
16
+ assert_raise { @subject.require_release 'rcsdb/folder/folder/file' }
17
+
18
+ assert_respond_to(Object.new, :require_release)
19
+ assert_respond_to(self, :require_release)
20
+
21
+ assert_raise(LoadError) { @subject.require_release 'rcs-project/file1' }
22
+ assert_raise(LoadError) { @subject.require_release 'rcs-project-release/file1' }
23
+ end
24
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestRcsCommon < Test::Unit::TestCase
4
+ def test_something_for_real
5
+ # flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
@@ -0,0 +1,40 @@
1
+ # encoding: utf-8
2
+
3
+ require "test/unit"
4
+
5
+ class SanitizeTest < Test::Unit::TestCase
6
+
7
+ def test_binary
8
+ input = "keep this and not those \x90 \x91 \x92"
9
+ output = 'keep this and not those '
10
+ assert_equal output, input.remove_invalid_chars
11
+ end
12
+
13
+ def test_punctuation
14
+ input = "keep all .,;:!? and also @#%&*()[]{}\"'\\/+="
15
+ output = "keep all .,;:!? and also @#%&*()[]{}\"'\\/+="
16
+ assert_equal output, input.remove_invalid_chars
17
+ end
18
+
19
+ def test_specials
20
+ input = "keep them \$ ^ |"
21
+ output = "keep them \$ ^ |"
22
+ assert_equal output, input.remove_invalid_chars
23
+ end
24
+
25
+ def test_strip_html_tags
26
+ input = "Strip <i>these</i> tags!"
27
+ output = "Strip these tags!"
28
+ assert_equal output, input.strip_html_tags
29
+
30
+ input = "<b>Bold</b> no more! <a href='more.html'>See more here</a>..."
31
+ output = "Bold no more! See more here..."
32
+ assert_equal output, input.strip_html_tags
33
+
34
+ input = "<div id='top-bar'>Welcome to my website!</div>"
35
+ output = "Welcome to my website!"
36
+ assert_equal output, input.strip_html_tags
37
+ end
38
+
39
+
40
+ end
@@ -0,0 +1,20 @@
1
+ require "helper"
2
+
3
+ class TestSerialization < Test::Unit::TestCase
4
+
5
+ # Fake test
6
+ def test_generate_prefix
7
+ type = 0xff
8
+ size = 0xaabbcc
9
+
10
+ assert_equal "\xCC\xBB\xAA\xFF".force_encoding('BINARY'), RCS::Serialization::prefix(type, size)
11
+ end
12
+
13
+ def test_decode_prefix
14
+ type, size = RCS::Serialization::decode_prefix("\xCC\xBB\xAA\xFF")
15
+
16
+ assert_equal type, 0xff
17
+ assert_equal size, 0xaabbcc
18
+ end
19
+
20
+ end
@@ -0,0 +1,90 @@
1
+ require "helper"
2
+
3
+ module RCS
4
+
5
+
6
+ class StatsManager < Stats
7
+ def initialize
8
+ @sections = {:minutes => 0, :hours => 60, :days => 24, :weeks => 7}
9
+ @template = {count: 0}
10
+ super
11
+ end
12
+ end
13
+
14
+ class TestStats < Test::Unit::TestCase
15
+
16
+ def setup
17
+
18
+ end
19
+
20
+ def test_single_minute
21
+ statistic = StatsManager.new
22
+ statistic.add count: 1
23
+ stats = statistic.stats
24
+
25
+ assert_equal 1, stats[:total][:count]
26
+ assert_equal 1, stats[:minutes][:last][0][:count]
27
+ assert_equal 1, stats[:hours][:last][0][:count]
28
+ assert_equal 1, stats[:days][:last][0][:count]
29
+ assert_equal 1, stats[:weeks][:last][0][:count]
30
+ end
31
+
32
+ def test_two_minute
33
+ statistic = StatsManager.new
34
+ statistic.add count: 1
35
+ statistic.calculate
36
+ statistic.add count: 1
37
+ stats = statistic.stats
38
+
39
+ assert_equal 2, stats[:total][:count]
40
+ assert_equal 1, stats[:minutes][:last][0][:count]
41
+ assert_equal 2, stats[:hours][:last][0][:count]
42
+ assert_equal 2, stats[:days][:last][0][:count]
43
+ assert_equal 2, stats[:weeks][:last][0][:count]
44
+ end
45
+
46
+ def test_one_hour
47
+ statistic = StatsManager.new
48
+
49
+ 1.upto(60) do
50
+ statistic.add count: 1
51
+ statistic.calculate
52
+ end
53
+
54
+ stats = statistic.stats
55
+
56
+ assert_equal 60, stats[:total][:count]
57
+ assert_equal 0, stats[:minutes][:last][0][:count]
58
+ assert_equal 0, stats[:hours][:last][0][:count]
59
+ assert_equal 60, stats[:days][:last][0][:count]
60
+ assert_equal 60, stats[:weeks][:last][0][:count]
61
+
62
+ assert_equal 1, stats[:minutes][:average][:count]
63
+ assert_equal 60, stats[:hours][:average][:count]
64
+ end
65
+
66
+ def test_one_day
67
+ statistic = StatsManager.new
68
+
69
+ 1.upto(1440) do
70
+ statistic.add count: 1
71
+ statistic.calculate
72
+ end
73
+
74
+ stats = statistic.stats
75
+
76
+ assert_equal 1440, stats[:total][:count]
77
+ assert_equal 0, stats[:minutes][:last][0][:count]
78
+ assert_equal 0, stats[:hours][:last][0][:count]
79
+ assert_equal 0, stats[:days][:last][0][:count]
80
+ assert_equal 1440, stats[:weeks][:last][0][:count]
81
+
82
+ assert_equal 1, stats[:minutes][:average][:count]
83
+ assert_equal 60, stats[:hours][:average][:count]
84
+ assert_equal 1440, stats[:days][:average][:count]
85
+ end
86
+
87
+
88
+ end
89
+
90
+ end #RCS
@@ -0,0 +1,20 @@
1
+ require 'helper'
2
+
3
+ class TestRcsCommon < Test::Unit::TestCase
4
+
5
+ def test_symbolize
6
+ src = {'one' => 1, 'two' => 2}
7
+ dst = {:one => 1, :two => 2}
8
+
9
+ assert_equal dst, src.symbolize
10
+ end
11
+
12
+ def test_symbolize_mixed
13
+ src = {'one' => 1, 'two' => 2, 1 => 'one', 2 => 'two'}
14
+ dst = {:one => 1, :two => 2, 1 => 'one', 2 => 'two'}
15
+
16
+ assert_equal dst, src.symbolize
17
+ end
18
+
19
+
20
+ end
@@ -0,0 +1,35 @@
1
+ require 'helper'
2
+
3
+ module RCS
4
+
5
+ class TestStatus < Test::Unit::TestCase
6
+
7
+ def test_disk
8
+ disk = SystemStatus.disk_free
9
+
10
+ # it should return a number
11
+ assert_kind_of Fixnum, disk
12
+ # it is a percentage
13
+ assert_equal true, (disk >= 0 and disk <= 100)
14
+ end
15
+
16
+ def test_load
17
+ load = SystemStatus.cpu_load
18
+
19
+ # it should return a number
20
+ assert_kind_of Fixnum, load
21
+ # it could be even greater than 100 on high load
22
+ assert_equal true, (load >= 0)
23
+ end
24
+
25
+ def test_process_cpu
26
+ cpu = SystemStatus.my_cpu_load('test')
27
+
28
+ # it should return a number
29
+ assert_kind_of Fixnum, cpu
30
+ # it is a percentage
31
+ assert_equal true, (cpu >= 0 and cpu <= 100)
32
+ end
33
+ end
34
+
35
+ end #RCS::
@@ -0,0 +1,56 @@
1
+ require "helper"
2
+
3
+ class TestTime < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @high_memory = "\x90\xd9\xcb\x01"
7
+ @low_memory = "\x50\x67\xe0\x63"
8
+ @high = 0x01cbd990
9
+ @low = 0x63e06750
10
+ end
11
+
12
+ def test_from_filetime
13
+ assert_equal '2011-03-03 10:47:28 UTC', Time.from_filetime(@high, @low).to_s
14
+ end
15
+
16
+ def test_from_filetime_has_millisec
17
+ assert_equal Time.from_filetime(@high, @low).usec, 436001
18
+ end
19
+
20
+ def test_unpack_from_memory
21
+ h = @high_memory.unpack('I').shift
22
+ l = @low_memory.unpack('I').shift
23
+ assert_equal '2011-03-03 10:47:28 UTC', Time.from_filetime(h, l).to_s
24
+ end
25
+
26
+ def test_to_filetime
27
+ date = Time.parse('2011-03-03 10:47:28 UTC')
28
+ date = Time.at(date.to_i, 436001)
29
+
30
+ filetime = date.to_filetime.pack('L*')
31
+
32
+ memory = (@low_memory + @high_memory).force_encoding('ASCII-8BIT')
33
+
34
+ assert_equal memory, filetime
35
+ end
36
+
37
+ def test_epoch
38
+ epoch = Time.from_filetime(0, 0)
39
+
40
+ assert_equal '1601-01-01 00:00:00 UTC', epoch.to_s
41
+ end
42
+
43
+ def test_from_and_to
44
+ now = Time.now.getutc
45
+
46
+ buff = StringIO.new
47
+
48
+ buff.write now.to_filetime.pack('L*')
49
+ buff.rewind
50
+ low, high = buff.read(8).unpack('L*')
51
+ check = Time.from_filetime(high, low)
52
+
53
+ # we explicitly ignore the usec, msec part
54
+ assert_equal now.to_s, check.to_s
55
+ end
56
+ end