ipcloak 1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 564d9c1f985c90eb0157cff65e71032ab5e830c3
4
+ data.tar.gz: 663317070aed89a580ebf3f5bad415b71e5e9c0a
5
+ SHA512:
6
+ metadata.gz: 9985d473e2e0c784b82dfe082d8fa36804f7f26457b9323b75fe3c89aca6ca481f857d94cb8c784d09b1a6b2baa99790a3ca1d3e5dace28bbe01e8029ddfc70c
7
+ data.tar.gz: 64f1aec5a4b6e75aeb0814138ebcf8691ae33d51bf9b0bc671946fb34a9d3d9d804757f5420f8bdc89cf69449657119858e885272e79192e229049212928d480
@@ -0,0 +1,4 @@
1
+ require "mkmf"
2
+ extension_name = "ipcloak"
3
+ dir_config extension_name
4
+ create_makefile extension_name
@@ -0,0 +1,157 @@
1
+ /*
2
+ * Charybdis: an advanced ircd
3
+ * ip_cloaking.c: provide user hostname cloaking
4
+ *
5
+ * Written originally by nenolod, altered to use FNV by Elizabeth in 2008
6
+ * Altered to be a ruby module by Xe in 2017
7
+ */
8
+
9
+ #include <ctype.h>
10
+ #include <ruby.h>
11
+
12
+ #define HOSTLEN 50
13
+
14
+ static void do_host_cloak_ip(const char *inbuf, char *outbuf);
15
+ static void do_host_cloak_host(const char *inbuf, char *outbuf);
16
+
17
+ VALUE Ipcloak = Qnil;
18
+
19
+ void Init_ipcloak();
20
+ VALUE method_ipcloak_ip(VALUE self, VALUE ipaddr);
21
+ VALUE method_ipcloak_host(VALUE self, VALUE host);
22
+
23
+ void Init_ipcloak() {
24
+ Ipcloak = rb_define_module("IPCloak");
25
+ rb_define_singleton_method(Ipcloak, "ip", method_ipcloak_ip, 1);
26
+ rb_define_singleton_method(Ipcloak, "host", method_ipcloak_host, 1);
27
+ }
28
+
29
+ /* Magic value for FNV hash functions */
30
+ #define FNV1_32_INIT 0x811c9dc5UL
31
+
32
+ u_int32_t
33
+ fnv_hash(const unsigned char *s, int bits)
34
+ {
35
+ u_int32_t h = FNV1_32_INIT;
36
+
37
+ while (*s) {
38
+ h ^= *s++;
39
+ h += (h<<1) + (h<<4) + (h<<7) + (h << 8) + (h << 24);
40
+ }
41
+ if (bits < 32)
42
+ h = ((h >> bits) ^ h) & ((1<<bits)-1);
43
+ return h;
44
+ }
45
+
46
+ static void
47
+ do_host_cloak_ip(const char *inbuf, char *outbuf)
48
+ {
49
+ /* None of the characters in this table can be valid in an IP */
50
+ char chartable[] = "ghijklmnopqrstuvwxyz";
51
+ char *tptr;
52
+ uint32_t accum = fnv_hash((const unsigned char*) inbuf, 32);
53
+ int sepcount = 0;
54
+ int totalcount = 0;
55
+ int ipv6 = 0;
56
+
57
+ strlcpy(outbuf, inbuf, HOSTLEN + 1);
58
+
59
+ if (strchr(outbuf, ':')) {
60
+ ipv6 = 1;
61
+
62
+ /* Damn you IPv6...
63
+ * We count the number of colons so we can calculate how much
64
+ * of the host to cloak. This is because some hostmasks may not
65
+ * have as many octets as we'd like.
66
+ *
67
+ * We have to do this ahead of time because doing this during
68
+ * the actual cloaking would get ugly
69
+ */
70
+ for (tptr = outbuf; *tptr != '\0'; tptr++)
71
+ if (*tptr == ':')
72
+ totalcount++;
73
+ } else if (!strchr(outbuf, '.'))
74
+ return;
75
+
76
+ for (tptr = outbuf; *tptr != '\0'; tptr++) {
77
+ if (*tptr == ':' || *tptr == '.') {
78
+ sepcount++;
79
+ continue;
80
+ }
81
+
82
+ if (ipv6 && sepcount < totalcount / 2)
83
+ continue;
84
+
85
+ if (!ipv6 && sepcount < 2)
86
+ continue;
87
+
88
+ *tptr = chartable[(*tptr + accum) % 20];
89
+ accum = (accum << 1) | (accum >> 31);
90
+ }
91
+ }
92
+
93
+ static void
94
+ do_host_cloak_host(const char *inbuf, char *outbuf)
95
+ {
96
+ char b26_alphabet[] = "abcdefghijklmnopqrstuvwxyz";
97
+ char *tptr;
98
+ uint32_t accum = fnv_hash((const unsigned char*) inbuf, 32);
99
+
100
+ strlcpy(outbuf, inbuf, HOSTLEN + 1);
101
+
102
+ /* pass 1: scramble first section of hostname using base26
103
+ * alphabet toasted against the FNV hash of the string.
104
+ *
105
+ * numbers are not changed at this time, only letters.
106
+ */
107
+ for (tptr = outbuf; *tptr != '\0'; tptr++) {
108
+ if (*tptr == '.')
109
+ break;
110
+
111
+ if (isdigit(*tptr) || *tptr == '-')
112
+ continue;
113
+
114
+ *tptr = b26_alphabet[(*tptr + accum) % 26];
115
+
116
+ /* Rotate one bit to avoid all digits being turned odd or even */
117
+ accum = (accum << 1) | (accum >> 31);
118
+ }
119
+
120
+ /* pass 2: scramble each number in the address */
121
+ for (tptr = outbuf; *tptr != '\0'; tptr++) {
122
+ if (isdigit(*tptr))
123
+ *tptr = '0' + (*tptr + accum) % 10;
124
+
125
+ accum = (accum << 1) | (accum >> 31);
126
+ }
127
+ }
128
+
129
+ VALUE method_ipcloak_ip(VALUE self, VALUE ip) {
130
+ char *data;
131
+ char res[HOSTLEN];
132
+
133
+ data = StringValueCStr(ip);
134
+ if (data == NULL) {
135
+ rb_raise(rb_eTypeError, "argument must be a string");
136
+ return Qnil;
137
+ }
138
+
139
+ do_host_cloak_ip(data, res);
140
+
141
+ return rb_str_new2(res);
142
+ }
143
+
144
+ VALUE method_ipcloak_host(VALUE self, VALUE host) {
145
+ char *data;
146
+ char res[HOSTLEN];
147
+
148
+ data = StringValueCStr(host);
149
+ if (data == NULL) {
150
+ rb_raise(rb_eTypeError, "argument must be a string");
151
+ return Qnil;
152
+ }
153
+
154
+ do_host_cloak_host(data, res);
155
+
156
+ return rb_str_new2(res);
157
+ }
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ipcloak
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.0'
5
+ platform: ruby
6
+ authors:
7
+ - Christine Dodrill
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-11-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake-compiler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description:
28
+ email:
29
+ executables: []
30
+ extensions:
31
+ - ext/ipcloak/extconf.rb
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ext/ipcloak/extconf.rb
35
+ - ext/ipcloak/ipcloak.c
36
+ homepage:
37
+ licenses: []
38
+ metadata: {}
39
+ post_install_message:
40
+ rdoc_options: []
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ requirements: []
54
+ rubyforge_project:
55
+ rubygems_version: 2.4.8
56
+ signing_key:
57
+ specification_version: 4
58
+ summary: IP scrambling for ruby developers
59
+ test_files: []