Skip to content
This repository has been archived by the owner on Feb 8, 2019. It is now read-only.

Fixes #8765: Add new password type 'pre-hashed' and 'script' #88

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/main/scala/com/normation/cfclerk/domain/Constraint.scala
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import net.liftweb.common._

class ConstraintException(val msg: String) extends Exception(msg)


trait VTypeWithRegex {
def regex:Option[RegexConstraint]
}
Expand Down Expand Up @@ -158,7 +157,6 @@ case class DateTimeVType(regex: Option[RegexConstraint] = None) extends VTypeCon
case class DateVType(regex: Option[RegexConstraint] = None) extends VTypeConstraint with VTypeWithRegex { override val name = "date" }
case class TimeVType(regex: Option[RegexConstraint] = None) extends VTypeConstraint with VTypeWithRegex { override val name = "time" }


//other types

// passwords
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,20 @@ object HashAlgoConstraint {
/*
* Actually do not hash the result
*/
object PLAIN extends HashAlgoConstraint {
object PLAIN extends HashAlgoConstraint {
override def hash(input:Array[Byte]) : String = new String(input, "UTF-8")
override val prefix = "plain"
}

object PreHashed extends HashAlgoConstraint {
override def hash(input:Array[Byte]) : String = new String(input, "UTF-8")
override val prefix = "pre-hashed"
}

object SCRIPT extends HashAlgoConstraint {
override def hash(input:Array[Byte]) : String = new String(input, "UTF-8")
override val prefix = "script"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't it have other impact in term of code ?
what is it expected to do when it's a script ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To evaluate this variable as a script.

But the main goal is to provide a way to identify that the user would like to do a script, and ease it's usability

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but there is nothing in code to change behaviour if it's a script ...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll let the evaluation do it for me.

Not a problem to me if it does nothing but i can identify and help the user to enter a script

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a problem either if other hashes containing script are evalutated.

In fact that's a plain text that indicate that you want to save a script, but maybe it's not containing one.

In fact It does not indicate that the values should be evaluated as a script, but only that the user wanted to enter a script in there

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

}
/*
* Simple standard hash: MD5, SHA-1,256,512
*/
Expand Down Expand Up @@ -136,7 +145,6 @@ object HashAlgoConstraint {
override val prefix = "linux-shadow-sha512"
}


/*
* AIX /etc/security/user hash, as explained here:
*
Expand Down Expand Up @@ -177,18 +185,17 @@ object HashAlgoConstraint {
override val prefix = "unix-crypt-des"
}


sealed trait DerivedPasswordType {
//name, for ex for unserialisation
def name: String ;
def name: String
//the total mapping from a hashalgo to another
def hash(h: HashAlgoConstraint): HashAlgoConstraint
}

final object DerivedPasswordType {

final case object AIX extends DerivedPasswordType {
final val name = "aix"
final val name = "AIX"

def hash(h: HashAlgoConstraint) = h match {
case LinuxShadowMD5 => AixMD5
Expand All @@ -199,7 +206,7 @@ object HashAlgoConstraint {
}

final case object Linux extends DerivedPasswordType {
final val name = "linux"
final val name = "Unix"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't it break something ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kept the constructor that use 'Linux', name is only used a display


def hash(h: HashAlgoConstraint) = h match {
case AixMD5 => LinuxShadowMD5
Expand All @@ -211,12 +218,10 @@ object HashAlgoConstraint {
//solaris, etc: todo
}


/////
///// Generic methods on algos
/////


def algorithms = values[HashAlgoConstraint]

/**
Expand All @@ -228,6 +233,8 @@ object HashAlgoConstraint {
def sort(algos: Set[HashAlgoConstraint]): Seq[HashAlgoConstraint] = {
def order(algo: HashAlgoConstraint): Int = algo match {
case PLAIN => 1
case PreHashed => 1
case SCRIPT => 1
case LinuxShadowMD5 => 21
case LinuxShadowSHA256 => 22
case LinuxShadowSHA512 => 23
Expand Down Expand Up @@ -263,7 +270,7 @@ object HashAlgoConstraint {
private[this] val format = """([\w-]+):(.*)""".r
def unserializeIn(algos: Set[HashAlgoConstraint], value:String): Box[(HashAlgoConstraint, String)] = value match {
case format(algo,h) => HashAlgoConstraint.fromStringIn(algos, algo) match {
case None => Failure(s"Unknown algorithm ${algo}. List of know algorithme: ${algoNames(algos)}")
case None => Failure(s"Unknown algorithm ${algo}. List of know algorithm: ${algoNames(algos)}")
case Some(a) => Full((a,h))
}
case _ => Failure(s"Bad format of serialized hashed value, expected format is: 'algorithme:hash', with algorithm among: ${algoNames(algos)}")
Expand Down