@@ -581,3 +581,49 @@ private class CipherOperation extends Cryptography::CryptographicOperation::Rang
581581 result = cipherNode .getCipherMode ( ) .getBlockMode ( )
582582 }
583583}
584+
585+ /** Predicates and classes modeling the `OpenSSL::Digest` module */
586+ private module Digest {
587+ private import codeql.ruby.ApiGraphs
588+
589+ /** A call that hashes some input using a hashing algorithm from the `OpenSSL::Digest` module. */
590+ private class DigestCall extends Cryptography:: CryptographicOperation:: Range instanceof DataFlow:: CallNode {
591+ Cryptography:: HashingAlgorithm algo ;
592+
593+ DigestCall ( ) {
594+ exists ( API:: MethodAccessNode call |
595+ call = API:: getTopLevelMember ( "OpenSSL" ) .getMember ( "Digest" ) .getMethod ( "new" )
596+ |
597+ this = call .getReturn ( ) .getAMethodCall ( [ "digest" , "update" , "<<" ] ) and
598+ algo .matchesName ( call .getCallNode ( )
599+ .getArgument ( 0 )
600+ .asExpr ( )
601+ .getExpr ( )
602+ .getConstantValue ( )
603+ .getString ( ) )
604+ )
605+ }
606+
607+ override Cryptography:: HashingAlgorithm getAlgorithm ( ) { result = algo }
608+
609+ override DataFlow:: Node getAnInput ( ) { result = super .getArgument ( 0 ) }
610+
611+ override Cryptography:: BlockMode getBlockMode ( ) { none ( ) }
612+ }
613+
614+ /** A call to `OpenSSL::Digest.digest` that hashes input directly without constructing a digest instance. */
615+ private class DigestCallDirect extends Cryptography:: CryptographicOperation:: Range instanceof DataFlow:: CallNode {
616+ Cryptography:: HashingAlgorithm algo ;
617+
618+ DigestCallDirect ( ) {
619+ this = API:: getTopLevelMember ( "OpenSSL" ) .getMember ( "Digest" ) .getMethod ( "digest" ) .getCallNode ( ) and
620+ algo .matchesName ( this .getArgument ( 0 ) .asExpr ( ) .getExpr ( ) .getConstantValue ( ) .getString ( ) )
621+ }
622+
623+ override Cryptography:: HashingAlgorithm getAlgorithm ( ) { result = algo }
624+
625+ override DataFlow:: Node getAnInput ( ) { result = super .getArgument ( 1 ) }
626+
627+ override Cryptography:: BlockMode getBlockMode ( ) { none ( ) }
628+ }
629+ }
0 commit comments