Browse Source

Hash VPN password

Baptiste Jonglez 11 years ago
parent
commit
89117e1455
1 changed files with 3 additions and 2 deletions
  1. 3 2
      coin/vpn/models.py

+ 3 - 2
coin/vpn/models.py

@@ -7,6 +7,7 @@ import ldapdb.models
 from ldapdb.models.fields import CharField, IntegerField, ListField
 
 from coin.models import CoinLdapSyncModel
+from coin import utils
 
 
 def validate_v4(address):
@@ -23,7 +24,6 @@ class VPNSubscription(CoinLdapSyncModel):
     # TODO: do some access control to prevent the user from changing this field
     activated = models.BooleanField(default=False)
     login = models.CharField(max_length=50)
-    # TODO: define which hash to use
     password = models.CharField(max_length=256)
     ipv4_endpoint = InetAddressField(validators=[validate_v4], blank=True)
     ipv6_endpoint = InetAddressField(validators=[validate_v6], blank=True)
@@ -41,7 +41,6 @@ class VPNSubscription(CoinLdapSyncModel):
         else:
             config = LdapVPNConfig.objects.get(pk=self.login)
         config.login = config.sn = self.login
-        # TODO: salt + hash the password
         config.password = self.password
         config.active = 'yes' if self.activated else 'no'
         config.ipv4_endpoint = str(self.ipv4_endpoint)
@@ -55,6 +54,8 @@ class VPNSubscription(CoinLdapSyncModel):
         pass
 
     def clean(self):
+        # Hash password if needed
+        self.password = utils.ldap_hash(self.password)
         # TODO: this should be factored for other technologies (DSL, etc)
         subnets = self.administrative_subscription.ip_subnet.all()
         # If saving for the first time and IP endpoints are not specified,