Skip to content

Commit 94acd41

Browse files
committed
Add case studies page and complete high-priority tasks
1 parent 372d716 commit 94acd41

File tree

3 files changed

+227
-1
lines changed

3 files changed

+227
-1
lines changed

www/TODO.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ This document outlines planned improvements and future tasks for the IPCrypt web
1010
- [x] Create implementation-specific pages with code examples
1111
- [x] Add a FAQ section addressing common questions
1212
- [x] Create a glossary of terms for technical concepts
13-
- [ ] Add case studies or examples of IPCrypt in real-world applications
13+
- [x] Add case studies or examples of IPCrypt in real-world applications
1414

1515
### Design Improvements
1616

www/_config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ navigation:
9595
url: /code-examples/
9696
- title: Resources
9797
url: /resources/
98+
- title: Case Studies
99+
url: /case-studies/
98100

99101
# Social links
100102
social_links:

www/pages/case-studies.md

Lines changed: 224 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,224 @@
1+
---
2+
layout: page
3+
title: IPCrypt Case Studies
4+
description: Real-world examples and applications of IPCrypt in various environments and use cases.
5+
permalink: /case-studies/
6+
---
7+
8+
# IPCrypt in Practice
9+
10+
This page showcases real-world examples of how IPCrypt can be used in various environments. These examples illustrate practical applications of IPCrypt's encryption modes.
11+
12+
## Network Logging and Analysis
13+
14+
### Privacy-Preserving Log Analysis
15+
16+
Network logs often contain IP addresses that may be considered personal data under privacy regulations. By using IPCrypt, organizations can maintain the utility of their logs while protecting user privacy.
17+
18+
```python
19+
# Example: Privacy-preserving logging with IPCrypt
20+
from ipcrypt import IPCrypt
21+
import logging
22+
23+
# Initialize IPCrypt with a secure key
24+
key = bytes.fromhex("0123456789abcdeffedcba9876543210")
25+
ipcrypt = IPCrypt(key)
26+
27+
def log_network_event(client_ip, event_type, timestamp):
28+
# Encrypt the IP address using deterministic mode
29+
encrypted_ip = ipcrypt.encrypt_deterministic(client_ip)
30+
31+
# Log the event with the encrypted IP
32+
logging.info(f"Event: {event_type}, IP: {encrypted_ip}, Time: {timestamp}")
33+
34+
# For internal analysis, we can still group by IP address
35+
# since deterministic mode produces consistent results
36+
return encrypted_ip
37+
```
38+
39+
**Benefits:**
40+
- Logs can still be analyzed for patterns and anomalies
41+
- IP addresses are protected from casual observation
42+
- Compliance with privacy regulations is improved
43+
- Original IPs can be recovered if necessary with the key
44+
45+
## Data Sharing Between Organizations
46+
47+
### Collaborative Security Research
48+
49+
Security researchers often need to share data about network attacks across organizational boundaries. Using IPCrypt's non-deterministic modes allows for secure sharing without revealing the actual IP addresses.
50+
51+
```python
52+
# Example: Sharing security data between organizations
53+
from ipcrypt import IPCrypt
54+
import os
55+
import json
56+
57+
# Each organization uses their own key
58+
org_key = bytes.fromhex("0123456789abcdeffedcba9876543210")
59+
ipcrypt = IPCrypt(org_key)
60+
61+
def prepare_data_for_sharing(attack_data):
62+
sanitized_data = []
63+
64+
for incident in attack_data:
65+
# Generate a random tweak for each sharing instance
66+
tweak = os.urandom(16)
67+
68+
# Use non-deterministic extended mode for maximum security
69+
encrypted_ip = ipcrypt.encrypt_ndx(incident["source_ip"], tweak)
70+
71+
# Replace the actual IP with the encrypted version
72+
incident_copy = incident.copy()
73+
incident_copy["source_ip"] = encrypted_ip
74+
incident_copy["tweak"] = tweak.hex() # Include the tweak for potential decryption
75+
76+
sanitized_data.append(incident_copy)
77+
78+
return json.dumps(sanitized_data)
79+
```
80+
81+
**Benefits:**
82+
- Attack patterns can be shared without exposing actual IP addresses
83+
- Each sharing instance uses different tweaks, preventing correlation
84+
- The original organization can still decrypt if needed
85+
- Recipient organizations can analyze patterns without seeing actual IPs
86+
87+
## Database Storage and Querying
88+
89+
### Searchable Encryption for IP Addresses
90+
91+
When storing IP addresses in databases, organizations often need to balance privacy with the ability to query and analyze the data. IPCrypt's deterministic mode enables this balance.
92+
93+
```sql
94+
-- Example database schema with IPCrypt-encrypted IP addresses
95+
96+
CREATE TABLE web_traffic (
97+
id SERIAL PRIMARY KEY,
98+
encrypted_ip_deterministic VARCHAR(39) NOT NULL, -- For querying
99+
encrypted_ip_nd TEXT, -- For maximum privacy
100+
request_path TEXT NOT NULL,
101+
user_agent TEXT,
102+
timestamp TIMESTAMP NOT NULL,
103+
response_code INTEGER
104+
);
105+
106+
-- Create an index on the deterministic version for efficient queries
107+
CREATE INDEX idx_web_traffic_ip ON web_traffic(encrypted_ip_deterministic);
108+
109+
-- Example query to find all requests from a specific IP (after encrypting it)
110+
SELECT request_path, timestamp, response_code
111+
FROM web_traffic
112+
WHERE encrypted_ip_deterministic = 'ENCRYPTED_IP_VALUE';
113+
114+
-- Example query to count requests by IP (privacy-preserving analytics)
115+
SELECT encrypted_ip_deterministic, COUNT(*) as request_count
116+
FROM web_traffic
117+
GROUP BY encrypted_ip_deterministic
118+
ORDER BY request_count DESC
119+
LIMIT 10;
120+
```
121+
122+
**Benefits:**
123+
- IP addresses are not stored in plaintext
124+
- Queries can still be performed efficiently using indexes
125+
- Analytics and grouping operations work as expected
126+
- Privacy is maintained while preserving functionality
127+
128+
## Cloud Service Integration
129+
130+
### Privacy-Preserving CDN Configuration
131+
132+
Content Delivery Networks (CDNs) often need IP addresses for configuration, such as IP-based access control. Using IPCrypt allows for secure management of these configurations.
133+
134+
```javascript
135+
// Example: Managing CDN IP allowlists with IPCrypt
136+
const { IPCrypt } = require('ipcrypt');
137+
const fs = require('fs');
138+
139+
// Initialize with a secure key
140+
const key = Buffer.from('0123456789abcdeffedcba9876543210', 'hex');
141+
const ipcrypt = new IPCrypt(key);
142+
143+
// Read the list of allowed IPs from a secure location
144+
const allowedIPs = fs.readFileSync('allowed_ips.txt', 'utf8')
145+
.split('\n')
146+
.filter(ip => ip.trim().length > 0);
147+
148+
// Encrypt the IPs for storage in the CDN configuration
149+
const encryptedAllowlist = allowedIPs.map(ip => {
150+
return ipcrypt.encryptDeterministic(ip);
151+
});
152+
153+
// Later, when checking if an IP is allowed
154+
function isIPAllowed(clientIP) {
155+
const encryptedIP = ipcrypt.encryptDeterministic(clientIP);
156+
return encryptedAllowlist.includes(encryptedIP);
157+
}
158+
```
159+
160+
**Benefits:**
161+
- IP allowlists can be managed without exposing actual IP addresses
162+
- Configuration files and databases don't contain plaintext IPs
163+
- Access control functionality works as expected
164+
- Reduced risk if configuration files are exposed
165+
166+
## Regulatory Compliance
167+
168+
### GDPR-Compliant Analytics
169+
170+
Under GDPR and similar regulations, IP addresses are considered personal data. IPCrypt can help organizations comply with these regulations while still collecting necessary analytics.
171+
172+
```python
173+
# Example: GDPR-compliant analytics collection
174+
from ipcrypt import IPCrypt
175+
import time
176+
177+
# Initialize IPCrypt with a secure key
178+
key = bytes.fromhex("0123456789abcdeffedcba9876543210")
179+
ipcrypt = IPCrypt(key)
180+
181+
class PrivacyCompliantAnalytics:
182+
def __init__(self):
183+
self.page_views = {}
184+
self.unique_visitors = set()
185+
186+
def record_page_view(self, client_ip, page_path):
187+
# Use deterministic encryption for consistent visitor counting
188+
encrypted_ip = ipcrypt.encrypt_deterministic(client_ip)
189+
190+
# Count the page view
191+
if page_path not in self.page_views:
192+
self.page_views[page_path] = 0
193+
self.page_views[page_path] += 1
194+
195+
# Count unique visitors
196+
self.unique_visitors.add(encrypted_ip)
197+
198+
def get_analytics_report(self):
199+
return {
200+
"total_page_views": sum(self.page_views.values()),
201+
"unique_visitors": len(self.unique_visitors),
202+
"popular_pages": sorted(self.page_views.items(),
203+
key=lambda x: x[1],
204+
reverse=True)
205+
}
206+
```
207+
208+
**Benefits:**
209+
- Analytics can be collected without storing personal data
210+
- Unique visitor counting still works accurately
211+
- No need to obtain explicit consent for IP storage
212+
- Reduced risk in case of data breaches
213+
214+
## Implementation Considerations
215+
216+
When implementing IPCrypt in real-world applications, consider the following:
217+
218+
1. **Key Management**: Securely store and manage encryption keys
219+
2. **Mode Selection**: Choose the appropriate encryption mode based on your specific needs
220+
3. **Performance**: For high-volume applications, consider caching or batch processing
221+
4. **Backup**: Ensure keys are securely backed up to prevent data loss
222+
5. **Documentation**: Clearly document the encryption approach for future reference
223+
224+
These case studies demonstrate how IPCrypt can be applied in various scenarios to balance operational needs with privacy considerations. By using the appropriate encryption mode for each use case, organizations can maintain functionality while enhancing privacy and security.

0 commit comments

Comments
 (0)