Skip to content

Commit

Permalink
Add warnings when using SigType fallbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
str4d committed Apr 2, 2017
1 parent 8c6ec8e commit 25539ed
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion txi2p/sam/session.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Copyright (c) str4d <str4d@mail.i2p>
# See COPYING for details.
from __future__ import print_function

import os
from parsley import makeProtocol
import sys
from twisted.internet import defer, error
from twisted.python import failure, log

Expand All @@ -12,6 +14,10 @@
from txi2p.sam.base import cmpSAM, SAMSender, SAMReceiver, SAMFactory


def eprint(*args, **kwargs):
print(*args, file=sys.stderr, **kwargs)


class SessionCreateSender(SAMSender):
def sendSessionCreate(self, samVersion, style, id, privKey=None, localPort=None, options={}, sigType=None):
msg = 'SESSION CREATE'
Expand Down Expand Up @@ -52,6 +58,7 @@ def create(self, result, destination=None, message=None):
message.startswith('SIGNATURE_TYPE') and \
not self.factory.sigType:
fallback = 'ECDSA_SHA256_P256' in message and 'DSA_SHA1' or 'ECDSA_SHA256_P256'
eprint('Warning: %s, falling back to %s' % (message, fallback))
self.sender.sendSessionCreate(
self.factory.samVersion,
self.factory.style,
Expand All @@ -76,7 +83,7 @@ def postLookup(self, dest):
try:
self.sender.transport.setTcpKeepAlive(1)
except AttributeError as e:
print e
eprint(e)
self.factory.sessionCreated(self, dest)


Expand Down Expand Up @@ -274,6 +281,7 @@ def destGenerated(self, result=None, pub=None, priv=None, message=None):
message.startswith('SIGNATURE_TYPE') and \
not self.factory.sigType:
fallback = 'ECDSA_SHA256_P256' in message and 'DSA_SHA1' or 'ECDSA_SHA256_P256'
eprint('Warning: %s, falling back to %s' % (message, fallback))
self.sender.sendDestGenerate(
self.factory.samVersion,
fallback)
Expand Down

0 comments on commit 25539ed

Please sign in to comment.